Class SQLite
- Namespace
- NominalSystems.SQL
- Assembly
- NominalSystems.SQL.dll
[Nominal] A SQL encoder/decoder for C# objects. This library will be able to manage SQLite databases and save and load objects and data to the file system.
public static class SQLite
- Inheritance
-
SQLite
Methods
AddColumn(SQLiteConnection, string, string)
Adds a new column to a particular table in the database. This will add a new column to the table with the specified name.
public static bool AddColumn(SQLiteConnection db, string table, string column)
Parameters
db
SQLiteConnectionThe SQLite connection
table
stringThe table to alter
column
stringThe name of the column to add
Returns
- bool
A successful addition of a column
Close(SQLiteConnection?)
Closes the connection to the database that was previously opened with a valid SQLite connection.
public static void Close(SQLiteConnection? db)
Parameters
db
SQLiteConnectionThe SQLite connection
CollectGC()
Clears all garbage from the SQLite connection. This will ensure any connections are closed and the garbage is collected.
public static void CollectGC()
ColumnCount(SQLiteConnection, string)
Returns the number of columns that exists in a particular table. This will be the current count.
public static int ColumnCount(SQLiteConnection db, string table)
Parameters
db
SQLiteConnectionThe SQLite connection
table
stringThe name of the table
Returns
- int
The number of columns that exist
ColumnNames(SQLiteConnection, string)
Returns the names of the columns in a table as an array of strings.
public static string[] ColumnNames(SQLiteConnection db, string table)
Parameters
db
SQLiteConnectionThe SQLite connection
table
stringThe name of the table
Returns
- string[]
An array of column names
ColumnTypes(SQLiteConnection, string)
Returns the list of column types defined within the column. These will be converted to strings describing the type of each column within the table.
public static string[] ColumnTypes(SQLiteConnection db, string table)
Parameters
db
SQLiteConnectionThe SQLite connection
table
stringThe name of the table
Returns
- string[]
An array of column types defined in the table
CreateTable(SQLiteConnection, string, params string[])
Creates a new table within the database with a given name and a list of columns to add. These columns will be by default given a TEXT data format.
public static bool CreateTable(SQLiteConnection db, string table, params string[] columns)
Parameters
db
SQLiteConnectionThe SQLite connection
table
stringThe name of the table
columns
string[]The array of column names to add
Returns
- bool
A successful creation of the table
DeleteColumn(SQLiteConnection, string, string)
Deletes a particular column from a table within the database. If it does not exist, this will return a false value.
public static bool DeleteColumn(SQLiteConnection db, string table, string column)
Parameters
db
SQLiteConnectionThe SQLite connection
table
stringThe name of the table
column
stringThe column to delete
Returns
- bool
A successful deletion flag
DeleteRecords(SQLiteConnection, string, string)
Deletes a number of records from a table within the database that meet a particular condition. This will return a success if at least one record is deleted.
public static bool DeleteRecords(SQLiteConnection db, string table, string condition)
Parameters
db
SQLiteConnectionThe SQLite connection
table
stringThe name of the table
condition
stringThe condition in which records will be deleted
Returns
- bool
A successful deletion of records flag
DeleteTable(SQLiteConnection, string)
Deletes a particular table from the SQLite database. If the table does not exist, this will return a false value.
public static bool DeleteTable(SQLiteConnection db, string table)
Parameters
db
SQLiteConnectionThe SQLite connection
table
stringThe name of the table
Returns
- bool
A successful deletion flag
ExportTable(SQLiteConnection, string, string)
Exports a particular table to a CSV file. This will overwrite the file if it already exists. It will take all data in the table and write it to the CSV file.
public static bool ExportTable(SQLiteConnection db, string table, string path)
Parameters
db
SQLiteConnectionThe SQLite connection
table
stringThe name of the table
path
stringThe path to the CSV file
Returns
- bool
A successful export of data
GetColumnIntegers(SQLiteConnection, string, string, string)
Returns an array of integer values from the table on a particular column that meets a condition. This will return the integers down the column of all selected records.
public static long[] GetColumnIntegers(SQLiteConnection db, string table, string column, string condition)
Parameters
db
SQLiteConnectionThe SQLite connection
table
stringThe name of the table
column
stringThe column to fetch
condition
stringThe condition in which the records will be selected
Returns
- long[]
The array of integer values down the column
GetColumnStrings(SQLiteConnection, string, string, string)
Returns an array of string values from the table on a particular column that meets a condition. This will return the strings down the column of all selected records.
public static string[] GetColumnStrings(SQLiteConnection db, string table, string column, string condition = "")
Parameters
db
SQLiteConnectionThe SQLite connection
table
stringThe name of the table
column
stringThe column to fetch
condition
stringThe condition in which the records will be selected
Returns
- string[]
The array of string values down the column
InsertRecord(SQLiteConnection, string, params object[])
Inserts a record into the table with the list of values associated with the record in the same order as the columns. This will return whether the record can be added.
public static bool InsertRecord(SQLiteConnection db, string table, params object[] values)
Parameters
db
SQLiteConnectionThe SQLite connection
table
stringThe name of the table
values
object[]The list of values to add to the record
Returns
- bool
A successful insert flag
Open(string)
Opens an SQL directory connection with a specific path. This will create an SQLite connection that can be used to interact with the database system.
public static SQLiteConnection? Open(string path)
Parameters
path
stringThe full file path for the directory
Returns
- SQLiteConnection
The SQLite connection
OpenMemory()
Opens an SQL directory connection using the 'memory' option, meaning that the database exists in the memory of the application and is not serialized to disk. This can improve performance for temporary data.
public static SQLiteConnection? OpenMemory()
Returns
- SQLiteConnection
The SQLite connection
Query(SQLiteConnection, string)
Queries the database using a generic query that can be applied to any column based on the SQL entered. This query can be used to fetch data and will return an array that is split by each record that is returned.
public static string[] Query(SQLiteConnection db, string query)
Parameters
db
SQLiteConnectionThe SQLite connection
query
stringThe SQL query to apply
Returns
- string[]
An array of records that are selected
RowCount(SQLiteConnection, string)
Returns the number of records that exists in a particular table. This will be the current count.
public static int RowCount(SQLiteConnection db, string table)
Parameters
db
SQLiteConnectionThe SQLite connection
table
stringThe name of the table
Returns
- int
The number of records that exist
SelectColumn(SQLiteConnection, string, string, string)
Selects the first record in the database table that meets the SQL condition that is passed in a returns the value of a particular column.
public static string SelectColumn(SQLiteConnection db, string table, string column, string condition)
Parameters
db
SQLiteConnectionThe SQLite connection
table
stringThe name of the table
column
stringThe column to select
condition
stringThe condition that will select the first record
Returns
- string
The column value associated with the record that meets the condition
SelectRecord(SQLiteConnection, string, string)
Selects the first record within a table that meets a particular condition. This will take in some SQL query condition and output all columns. The resulting array of strings will contain the data from the columns in the order that they are stored in the table.
public static string[] SelectRecord(SQLiteConnection db, string table, string condition)
Parameters
db
SQLiteConnectionThe SQLite connection
table
stringThe name of the table
condition
stringThe condition to select the first record
Returns
- string[]
An array of values within the columns of the record
SelectRecord(SQLiteConnection, string, string, params string[])
Selects the first record within a table that meets a particular condition. This will take in some SQL query condition and the list of columns to output. The resulting array of strings will contain the data from the columns in the order that they are provided.
public static string[] SelectRecord(SQLiteConnection db, string table, string condition, params string[] columns)
Parameters
db
SQLiteConnectionThe SQLite connection
table
stringThe name of the table
condition
stringThe condition to select the first record
columns
string[]The array of column names to select
Returns
- string[]
An array of values within the columns of the record
TableExists(SQLiteConnection, string)
Returns whether a particular table in an SQLite database exists. If the table cannot be found, then this function will return false.
public static bool TableExists(SQLiteConnection db, string table)
Parameters
db
SQLiteConnectionThe SQLite connection
table
stringThe name of the table to find
Returns
- bool
A flag whether the table exists in the database
TableNames(SQLiteConnection)
Returns a string array of all table names that exist in the SQLite database.
public static string[] TableNames(SQLiteConnection db)
Parameters
db
SQLiteConnectionThe SQLite connection
Returns
- string[]
A string array of all table names in the database
Validate(SQLiteConnection?)
Validates an SQLite connection to ensure it is open and safely existing.
public static bool Validate(SQLiteConnection? db)
Parameters
db
SQLiteConnectionThe SQLite connection
Returns
- bool
A valid SQLite connection flag