Db Table Data
DbTableData represents a base class for constructing data classes that work with instances of DatabaseIfc. Specifically, DbTableData provide the ability to push data into a table. Thus, subclasses of DbTableData must provide information about the primary key of the table and whether the key is an auto-increment type field.
Example usage:
data class Person(var id: Int, var name:String, var age:Int): DbTableData("Persons", listOf("id"), true)
db.selectDbDataInto(::Person)
Ideally, the data class should be defined with 'var' properties that have default values. This facilitates the creation of instances. Any 'val' properties are not recognized as table fields because they are not mutable. You can have 'val' properties in the primary constructor or in the class body; however, they will not be processed as table fields.
Assume that db holds an instance to a database that has a table called, Persons, with the fields (id, name and age) as the sole columns, in that order. The data will be extracted from the database table and instances of the data class created and filled with the data from the table. As long as the data class properties match in order and with compatible types with the fields/columns of the database, then the instances will be created and filled.
The tableName should be a valid table name within a database if used with a database.
The property keyFields holds the names of the fields involved within the primary key. There must be at least one field supplied. That is the list must not be empty. And, if the auto-increment property is set to true, there must be one and only one element in the list.
The property autoIncField indicates if the referenced table has an auto-increment field as the primary key. This information can be used when pushing data from the data class into the database to ignore the property listed in the constructor of the data class.
Inheritors
Properties
The number of columns of data. The number of public mutable properties including any auto-increment field
The number of fields to insert. If there is an auto-increment field then it is not included.
The number of fields to update. This does not include the fields within the primary key
The optional name of the schema holding the table for the related data. If supplied it cannot be empty/blank and any white space will be replaced with underscore characters.
Functions
Creates a string representation of a CREATE TABLE SQL statement that could create a table that would hold the data associated with the DbTableData. The resulting string maps the property KTypes to suitable SQL types via DbTableData.toSQLTypeString. If there is a primary key specification, it is captured in the CREATE TABLE statement. Any NOT NULL specifications are also captured. There will not be any foreign key specifications because DbTableData does not specify them. Also, since there is no SQL standard for an auto-increment primary key, the autoIncField specification is ignored. The purpose here is to get a quick and dirty table representation. If additional specifications are required the user could formulate ALTER TABLE statements or better yet use one of the many libraries available for more advanced SQL work. If schemaName is supplied, then the CREATE TABLE statement begins with "CREATE TABLE schemaName.tableName ". If the schema name is not specified, the statement begins with "CREATE TABLE tableName "
Extracts the value of the public mutable properties of a data class If the object is not an instance of a data class, then the returned map will be empty. The map contains the pairs of (name, value) where name is the name of the public, mutable property and value is the current value of the property
Extracts the property of the public mutable properties of a data class Classifies each property whether it can be converted to a numeric value via isNumericConvertable(). All non-numeric mutable properties are considered TEXT; otherwise, they are considered NUMERIC.
The map will contain the fields and their values that are designated as part of the primary key
Extracts the current value of the fields that are designated as part of the primary key in the order in which the properties are listed within the class definition
Extracts the property of the public mutable properties of a data class If the object is not an instance of a data class, then the returned map will be empty. The map contains the pairs of (name, property) where name is the name of the public property and property is the reflection property
The map will contain all the fields by name with their values without an auto-increment field if it exists
The map will contain the fields and their values that are not designated as part of the primary key
Extracts the names of the public, mutable properties of a data class in the order in which they are declared in the primary constructor.
Extracts the value of the public, mutable properties of a data class in the order in which they are declared in the primary constructor.
Extracts the values of the public, mutable properties of a data class in the order in which they are declared in the primary constructor.
Extracts the names of the fields that can be updated or inserted by accounting for an auto-increment key field
Extracts the value of the public, mutable properties of a data class in the order in which they are declared in the primary constructor not including the fields designated as being within the primary key. We assume that the values returned correspond to data that must be used to update a record within the database table. Thus, we assume that the user will not update the values of the fields within the primary key. The returned values are in the order of the properties listed in the DbTableData class, not including the primary key fields.
Checks if an autoIncField exists
Returns a string representation of a table insert statement. See DatabaseIfc.insertIntoTableStatementSQL
Sets the value of the auto-increment field based on the supplied value
Sets the values of the public mutable properties of a data class to the values supplied. If the object is not an instance of a data class then nothing happens. The size of the supplied list must be the same as the number of the mutable properties and the type of each element in the supplied list must match the type of the mutable property
Sets the values of the public mutable properties of a data class to the values supplied. If the object is not an instance of a data class then nothing happens. The row from a TabularFile must map to the property values
Returns a string representation of a table update statement. See DatabaseIfc.updateTableStatementSQL