abstracted remote database helper - meitarsh/m.s-aluminium-manager-app GitHub Wiki
Remote SQL Helper Class (remote_helper.kt)
actually more of a interface
is an abstract class defining what is expected on the software when calling for updates or database read
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
in this stage, we should link all the previously mentioned variables to their matching strings.xml representation
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
END remote_helper.kt
table dataclass object interface (table_dataclass.kt)
actually more of a interface of what is expected on basic database representation of an item (be it remote or local)
a String representing and identifying the data type and its value
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
` gives the current username, empty if before a connection was done`
`returns true if connection is valid, false otherwise`
` gets the latest SQL Exception (could be as a result of bad database entry\bad query) as well as connection issues`
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
`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())
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
disconnects user from MSSQL, clearing connection (username stays though)
`development oriented: converts a database select query vector of hashmap to a single string`
`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`
refreshes the currently used context, in case the previous one was closed
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`
adds quotes for any string sent, for MSSQL case (that's how strings are sent in MSSQL)
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