abstracted remote database helper - meitarsh/m.s-aluminium-manager-app GitHub Wiki

actually more of a interface

is an abstract class defining what is expected on the software when calling for updates or database read

Requirements

first you must extend this class and create variables for each matching requirement on your database (database name, table name, variable names and their types), at this stage, all of the mentioned values couldn't be read from strings.xml file yet, so they should be empty

public fun init_variables(context: Context)

in this stage, we should link all the previously mentioned variables to their matching strings.xml representation

fun make_type_map(): HashMap<String, String>

in this stage, we should make a HashMap that each key is variable name on our database and each value is the variable type

protected abstract fun push_update(obj: table_dataclass, map:HashMap<String,String>, context: Context)

in this stage, we should read the object and see if it is matching our data type, and send its values to the remote database using the [remote_SQL_Helper](https://github.com/meitarsh/m.s-aluminium-manager-app/blob/master/src/app/src/main/java/com/example/chaosruler/msa_manager/services/remote_SQL_Helper.kt) class

actually more of a interface of what is expected on basic database representation of an item (be it remote or local)

Requirements

override public fun toString():String

a String representing and identifying the data type and its value

public fun copy(): table_dataclass

a copy constructor

remote SQL Helper (remote_SQL_Helper.kt)

an object representing a connection to MSSQL database using jtds driver, every function is done on a companion object therefore we are not required to create an objectified manner of this class

fun getusername():String

` gives the current username, empty if before a connection was done`

fun isValid():Boolean

 `returns true if connection is valid, false otherwise`

fun getSQLException():SQLException

   ` gets the latest SQL Exception (could be as a result of bad database entry\bad query) as well as connection issues`

Requirement to applicance function!

fun Connect(con:Context,user: String, pass: String): Boolean

a function that connects to the database using the specified username and password, context is sent to load configuration values, returns true if connection was successful with specified username and password, false otherwise

fun get_all_table(db: String, table: String): Vector<HashMap<String, String>>

`gives me all the database values from the database and table sent as parameters in a Vector (representing rows) of Hashmap (representing columns), keys in the hashmap represent variable name, the value represents the `

data value, call is threadded bust is blocked!

fun select_columns_from_db_with_where(db: String, table: String, colm_to_type:HashMap<String,String>, where_column:String?,where_compare:String?): Vector<HashMap<String, String>>

similar to previous call, also called with a thread and a block to wait for that thread, it filters data with where_to criteria to correspond to variablename, and where_compare to corresond to variable value, the variable type map has to be sent in colm_to_type value (easily accessed by API call make_typemap())

fun run_command(command:String): Boolean

runs the specified raw SQL command as it is, returns true if command was successfull, false otherwise it is ran within a thread but function is blocked

fun Disconnect()

disconnects user from MSSQL, clearing connection (username stays though)

fun VectorToString(vector: Vector<HashMap<String, String>>?): String

 `development oriented: converts a database select query vector of hashmap to a single string`

public fun isAlive():Boolean

`checks that connection is still alive, returns true if connection is alive, false otherwise, is ran from within a thread but function call is blocked`

fun refresh_context(con: Context)

refreshes the currently used context, in case the previous one was closed

fun ReConnect():Boolean

case we got offline somehow, reconnects to database, calls internally on each query

fun construct_add_str(db: String, table: String, vector: Vector, map: HashMap<String, String>):String

constructs an MSSQL add query with a database name matching db, table name matching table, the variable names of what we want variables we want to write to are sent in the vector (the value of what we should add) and the variable name is sent also in the HashMap keys, with a matching variable value in the value

fun construct_remove_str(db: String, table: String, where_clause: String, compare_to: Array, type: String):String

constructs a delete query for MSSQL with a database name matching db, table name matching table, filtering variable name of what we should delete is sent in the where_clause, and list of matching variable values should be sent in compare_to, the variable type should be sent in type

fun construct_update_str(db: String, table: String, where_clause: String, compare_to: Array, type: String, update_to: HashMap<String, String>):String

constructs an update query for MSSQL where database name is db, table name is table, matching variable name criteria to filter is in the where_clause parameter, and matching list of variables we should compare to is sent in the compare_to parameter, the variable type is sent on the type parameter, and what we should update is sent on the update_to parameter that its keys represent the variable names and the values represent the hashmap values

fun construct_update_str_multiwhere_text(db: String, table: String, where_clause:HashMap<String,String>, all_type:String, update_to: HashMap<String, String>):String

`very similar call to previous function, only the where_clause is multi_parameter (but has to be same type!) and is compared in AND logical link matter`

fun add_quotes(str:String):String = "'$str'"

adds quotes for any string sent, for MSSQL case (that's how strings are sent in MSSQL)

fun nirmol_input(input:HashMap<String,String>,types:HashMap<String,String>)

gets a list of variable names and values in the input Hashmap, and their corresponding types with the types hashmap (key : variable name, value: the type), if type is a stringfied represntation, quotes are automaticily added to the input hashmap

⚠️ **GitHub.com Fallback** ⚠️