Database

SplashKit Database allows you to create, query and otherwise manipulate a database.

SplashKit's database library allows you to easily create or load databases and to perform queries on them. To get started with databases in SplashKit, the first thinkg you need to do is to load or create a database file. You can do this by calling the Open Database(string Name) function.

Functions

Database Named

Retrieves a Database that has been loaded into SplashKit.

Return Type

Database

Returns the Database that has been loaded with the specified Name using Open Database.

Parameters
Name Type Description
Name

String

The name of the database to return.

Signatures
database database_named(string name)
public static Database Database.DatabaseNamed(string name);
public static Database SplashKit.DatabaseNamed(string name);
function DatabaseNamed(name: String): Database
def database_named(name):

Free All Databases

Releases all of the databases which have been loaded.

Signatures
void free_all_databases()
public static void Database.FreeAllDatabases();
public static void SplashKit.FreeAllDatabases();
procedure FreeAllDatabases()
def free_all_databases():

Free All Query Results

Frees all of the databases which have been loaded.

Signatures
void free_all_query_results()
public static void Database.FreeAllQueryResults();
public static void SplashKit.FreeAllQueryResults();
procedure FreeAllQueryResults()
def free_all_query_results():

Free Database

Free Database

Frees the SplashKit resources associated with the database.

Parameters
Name Type Description
Db To Close

Database

The Database whose resources should be released.

Signatures
void free_database(database db_to_close)
public void Database.FreeDatabase();
public static void SplashKit.FreeDatabase(Database dbToClose);
procedure FreeDatabase(dbToClose: Database)
def free_database(db_to_close):

Free Database

Frees the SplashKit resources associated with the database at a given name.

Parameters
Name Type Description
Name Of Db To Close

String

The String denoting where the database is which should be released.

Signatures
void free_database(string name_of_db_to_close)
public static void Database.FreeDatabase(string nameOfDbToClose);
public static void SplashKit.FreeDatabase(string nameOfDbToClose);
procedure FreeDatabase(nameOfDbToClose: String)
def free_database_named(name_of_db_to_close):

Free Query Result

Releases the SplashKit resources associated with the query.

Parameters
Name Type Description
Query

Query Result

The Query Result whose resources should be released.

Signatures
void free_query_result(query_result query)
public void QueryResult.FreeQueryResult();
public static void SplashKit.FreeQueryResult(QueryResult query);
procedure FreeQueryResult(query: QueryResult)
def free_query_result(query):

Get Next Row

Gets the next row available on a given Query Result.

Return Type

Boolean

Returns a Boolean which represents if there was a valid row of data to move to.

Parameters
Name Type Description
Db Result

Query Result

The Query Result to move to the next row on.

Signatures
bool get_next_row(query_result db_result)
public bool QueryResult.GetNextRow();
public static bool SplashKit.GetNextRow(QueryResult dbResult);
function GetNextRow(dbResult: QueryResult): Boolean
def get_next_row(db_result):

Has Database

Determines if SplashKit has a database loaded for the supplied name. This checks against all databases loaded, those loaded without a name are assigned the filename as a default. If this returns False, you may want to use Load Database to load in a specific database and give it the desired name.

Return Type

Boolean

Returns True if a database with the given Name has has been loaded.

Parameters
Name Type Description
Name

String

The name of the database you want to check for. This will match the name you used when opening the database in open_database

Signatures
bool has_database(string name)
public static bool Database.HasDatabase(string name);
public static bool SplashKit.HasDatabase(string name);
function HasDatabase(name: String): Boolean
def has_database(name):

Has Row

Checks if a given Query Result has a valid row of data.

Return Type

Boolean

Returns a Boolean which represents if there was a valid row of data.

Parameters
Name Type Description
Db Result

Query Result

The Query Result to check for a valid row of data on.

Signatures
bool has_row(query_result db_result)
public bool QueryResult.HasRow { get }
public static bool SplashKit.HasRow(QueryResult dbResult);
function HasRow(dbResult: QueryResult): Boolean
def has_row(db_result):

Open Database

Loads or creates, and returns a database.

The supplied Filename is the name of the file of the database. The supplied Name indicates the name to use to refer to this Database. The Database can then be retrieved by passing this Name to the Database Named function. If the database file does not exist, it will be created for you.

Return Type

Database

A new Database with the initialised values provided.

Parameters
Name Type Description
Name

String

The name used to refer to the database.

Filename

String

The filename used to locate the database to use.

Signatures
database open_database(string name, string filename)
public static Database SplashKit.OpenDatabase(string name, string filename);
public Database(string name, string filename);
function OpenDatabase(name: String; filename: String): Database
def open_database(name, filename):

Query Column For Boolean

Queries a given column in the current row of the Query Result for a bool.

Return Type

Boolean

Returns the Boolean which is the data at that column.

Parameters
Name Type Description
Db Result

Query Result

The Query Result to perform the query on.

Col

Integer

The column you would like to query data from.

Signatures
bool query_column_for_bool(query_result db_result, int col)
public bool QueryResult.QueryColumnForBool(int col);
public static bool SplashKit.QueryColumnForBool(QueryResult dbResult, int col);
function QueryColumnForBool(dbResult: QueryResult; col: Integer): Boolean
def query_column_for_bool(db_result, col):

Query Column For Double

Queries a given column in the current row of the Query Result for a double.

Return Type

Double

Returns the Double which is the data at that column.

Parameters
Name Type Description
Db Result

Query Result

The Query Result to perform the query on.

Col

Integer

The column you would like to query data from.

Signatures
double query_column_for_double(query_result db_result, int col)
public double QueryResult.QueryColumnForDouble(int col);
public static double SplashKit.QueryColumnForDouble(QueryResult dbResult, int col);
function QueryColumnForDouble(dbResult: QueryResult; col: Integer): Double
def query_column_for_double(db_result, col):

Query Column For Integer

Queries a given column in the current row of the Query Result for an integer.

Return Type

Integer

Returns the Integer which is the data at that column.

Parameters
Name Type Description
Db Result

Query Result

The Query Result to perform the query on.

Col

Integer

The column you would like to query data from.

Signatures
int query_column_for_int(query_result db_result, int col)
public int QueryResult.QueryColumnForInt(int col);
public static int SplashKit.QueryColumnForInt(QueryResult dbResult, int col);
function QueryColumnForInt(dbResult: QueryResult; col: Integer): Integer
def query_column_for_int(db_result, col):

Query Column For String

Queries a given column in the current row of the Query Result for a string.

Return Type

String

Returns the String which is the data at that column.

Parameters
Name Type Description
Db Result

Query Result

The Query Result to perform the query on.

Col

Integer

The column you would like to query data from.

Signatures
string query_column_for_string(query_result db_result, int col)
public string QueryResult.QueryColumnForString(int col);
public static string SplashKit.QueryColumnForString(QueryResult dbResult, int col);
function QueryColumnForString(dbResult: QueryResult; col: Integer): String
def query_column_for_string(db_result, col):

Query Success

Checks if the most recent query at the given Query Result was a success or failure.

Return Type

Boolean

Returns whether or not the query was a success or failure represented as a Boolean.

Parameters
Name Type Description
Db Result

Query Result

The Query Result to check the success of.

Signatures
bool query_success(query_result db_result)
public bool QueryResult.Successful { get }
public static bool SplashKit.QuerySuccess(QueryResult dbResult);
function QuerySuccess(dbResult: QueryResult): Boolean
def query_success(db_result):

Query Type Of Col

Queries a given column in the current row of the Query Result for the data type at its postition.

Return Type

String

Returns a String which is the name of the data type being stored. - Could return: Integer, Float, Text, Null.

Parameters
Name Type Description
Db Result

Query Result

The Query Result to perform the query on.

Col

Integer

The column you would like to know the data type of

Signatures
string query_type_of_col(query_result db_result, int col)
public string QueryResult.QueryTypeOfCol(int col);
public static string SplashKit.QueryTypeOfCol(QueryResult dbResult, int col);
function QueryTypeOfCol(dbResult: QueryResult; col: Integer): String
def query_type_of_col(db_result, col):

Reset Query Result

Resets a query_result back to its initial state, ready to be re-executed.

Parameters
Name Type Description
Db Result

Query Result

The Query Result to reset.

Signatures
void reset_query_result(query_result db_result)
public void QueryResult.ResetQueryResult();
public static void SplashKit.ResetQueryResult(QueryResult dbResult);
procedure ResetQueryResult(dbResult: QueryResult)
def reset_query_result(db_result):

Rows Changed

Calculates the number of row changed in the database at the last time a changing query was performed on the given database.

Return Type

Integer

Returns the Integer which represents how many rows were changed in the database.

Parameters
Name Type Description
Db

Database

The database to check how many rows changed.

Signatures
int rows_changed(database db)
public int Database.RowsChanged();
public static int SplashKit.RowsChanged(Database db);
function RowsChanged(db: Database): Integer
def rows_changed(db):

Run Sql

Run Sql

Returns the Query Result for the query passed into Sql.

Return Type

Query Result

Returns the Query Result which represents the result of perfoming Sql on Db.

Parameters
Name Type Description
Db

Database

The database to perform Sql on.

Sql

String

The sql statement to perform on Db.

Signatures
query_result run_sql(database db, string sql)
public QueryResult Database.RunSql(string sql);
public static QueryResult SplashKit.RunSql(Database db, string sql);
function RunSql(db: Database; sql: String): QueryResult
def run_sql(db, sql):

Run Sql

Returns the Query Result for the query passed into Sql.

Return Type

Query Result

Returns the Query Result which represents the result of perfoming Sql on the database at Database Name.

Parameters
Name Type Description
Database Name

String

The string name of the database to perform Sql on.

Sql

String

The sql statement to perform on the database at Database Name.

Signatures
query_result run_sql(string database_name, string sql)
public static QueryResult Database.RunSql(string databaseName, string sql);
public static QueryResult SplashKit.RunSql(string databaseName, string sql);
function RunSql(databaseName: String; sql: String): QueryResult
def run_sql_from_name(database_name, sql):

Types

Database

The Database type is used to refer to databases that can be manipulated by the SplashKit database code. Databases are:

  • opened with Open Database,

  • and must be released using Free Database (to release a specific database) or Delete All Databases (to release all loaded databases).

Query Result

The Query Result type is used to store the result of performing a query on the database. It can: