Skip to content

Instantly share code, notes, and snippets.

@BigETI
Created August 30, 2019 20:29
Show Gist options
  • Save BigETI/e984f056fdc0f7aa14573c43e780e441 to your computer and use it in GitHub Desktop.
Save BigETI/e984f056fdc0f7aa14573c43e780e441 to your computer and use it in GitHub Desktop.

The SQLite 3 API provides making prepared statements, managing backups, working with shared caches and providing mutexes to implement multi threading. The current implementation at some well known multiplayer mod misses a lot of useful features. So that is why I want propose additional natives for the database API.

  • SQLite:SQLite_Open(const path[], SQLiteOpenMode:openModeFlags):Open a SQLite database with support for file open mode flags and opening databases in a shared cache mode
  • SQLite:SQLite_OpenLegacy(const path[]): This function exists to be compatible with db_open
  • SQLite_Close(SQLite:database): Closes a SQLite database (db_close)
  • SQLite_CloseAll: Closes all SQLite databases
  • SQLite_CreateStatement(SQLite:database, const sql[]): Creates a prepared statement
  • SQLiteStatement:SQLite_CreateStatementThreaded(SQLite:database, const sql[], const callback[]): Creates a prepared statement in another thread
  • SQLite_DestroyStatement(SQLiteStatement:statement): Destroys a prepared statement
  • SQLiteStepResult:SQLite_Step(SQLiteStatement:statement): Executes a step for a prepared statement (useful for debugging prepared statements)
  • SQLiteJob:SQLite_StepThreaded(SQLite:database, SQLiteStatement:statement, const callback[]): SQLite_Step in another thread
  • SQLiteResult:SQLite_Query(SQLite:database, const sql[]): db_query but with overload for prepared statements which finalizes prepared statements
  • SQLiteJob:SQLite_QueryThreaded(SQLite:database, const sql[], const callback[]): It's just SQLite_Query but multi threaded
  • SQLiteResult:SQLite_QueryStatement(SQLiteStatement:statement): db_query but with overload for prepared statements which finalizes prepared statements
  • SQLiteJob:SQLite_QueryStatementThreaded(SQLiteStatement:statement, const callback[]): It's just SQLite_Query but multi threaded
  • SQLite_FreeResult(SQLiteResult:result): Free result (db_free_result)
  • SQLite_NumRows(SQLiteResult:result): Get number of rows (db_num_rows)
  • SQLite_NextRow(SQLiteResult:result): Fetch next row (db_next_row)
  • SQLite_NumFields(SQLiteResult:result): Get number of fields (db_num_fields)
  • SQLite_FieldName(SQLiteResult:result, columnIndex): Get field name (db_field_name)
  • SQLite_GetField(SQLiteResult:result, columnIndex, result[], resultSize = sizeof result): Get field as string (db_get_field)
  • SQLite_GetFieldAssoc(SQLiteResult:result, const field[], result[], resultSize = sizeof result): Get field as string by field name (db_get_field_assoc)
  • SQLite_GetFieldInt(SQLiteResult:result, columnIndex): Get field as integer (db_get_field_int)
  • SQLite_GetFieldAssocInt(SQLiteResult:result, columnIndex, const field[]): Get field as integer by field name (db_get_field_assoc_int)
  • Float:SQLite_GetFieldFloat(SQLiteResult:result, columnIndex): Get field as a floating point number (db_get_field_float)
  • Float:SQLite_GetFieldAssocFloat(SQLiteResult:result, columnIndex, const field[]): Get field as a floating point number by field name (db_get_field_assoc_float)
  • ForeignPointer:SQLite_GetMemHandle(SQLite:database): Gets the memory handle of a database (db_get_mem_handle)
  • ForeignPointer:SQLite_GetResultMemHandle(SQLiteResult:result): Gets the memory handle of a result (db_get_result_mem_handle)
  • SQLite_CreateBackup(SQLite:destination, const destinationName[], SQLite:source, const sourceName[]): Creates a database backup
  • SQLite_CreateBackupThreaded(SQLite:destination, SQLite:source, const callback[]): SQLite_CreateBackup in another thread
  • SQLiteJobStatus:SQLite_GetJobStatus(SQLiteJob:job)
  • SQLite_AbortJob(SQLiteJob:job)
  • SQLite_DebugOpenFiles(): Debug open files (db_debug_openfiles)
  • SQLite_DebugOpenResults(): Debug open results (db_debug_openresults)

Internally there will be support for URI's, automatic locks on transaction, callbacks for error messages and etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment