Author Topic: SQLite v. 3.7.6.3 Headers  (Read 8072 times)

0 Members and 1 Guest are viewing this topic.

Offline José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2481
  • User-Rate: +204/-0
SQLite v. 3.7.6.3 Headers
« on: June 01, 2011, 12:31:06 AM »
 
About SQLite

SQLite is a small C library that implements a self-contained, embeddable, zero-configuration SQL database engine. Features include:

  • Transactions are atomic, consistent, isolated, and durable (ACID) even after system crashes and power failures.
  • Zero-configuration - no setup or administration needed.
  • Implements most of SQL92
  • A complete database is stored in a single disk file.
  • Database files can be freely shared between machines with different byte orders.
  • Supports terabyte-sized databases and gigabyte-sized strings and blobs.
  • Small code footprint:  less than 250KiB fully configured or less than 150KiB with optional features omitted.
  • Faster than popular client/server database engines for most common operations.
  • Simple, easy to use API.
  • TCL bindings included. Bindings for many other languages  available separately.
  • Well-commented source code with over 98% test coverage.
  • Available as a  single ANSI-C source-code file that you can easily drop into another project.
  • Self-contained: no external dependencies.
  • Sources are in the public domain. Use for any purpose.

The SQLite distribution comes with a standalone command-line access program (sqlite) that can be used to administer an SQLite database and which serves as an example of how to use the SQLite library.

SQLite website: http://www.sqlite.org/

The attached file contains my translation of the SQLite headers to PowerBASIC.
« Last Edit: August 06, 2011, 02:34:10 PM by José Roca »

Offline José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2481
  • User-Rate: +204/-0
SQLite v. 3.7.6.3 Example: Creating a database
« Reply #1 on: June 01, 2011, 12:31:54 AM »
 
The following example demonstrates how to create a database using SQLite.

Code: [Select]
' ########################################################################################
' Sqlite example
' Creates a dabase.
' ########################################################################################

' SED_PBCC
#COMPILE EXE
#DIM ALL
#INCLUDE "WINDOWS.INC"
#INCLUDE "SQLITE3.INC"

$TEST_DATABASE = "TESTDB.SQLITE"

' ========================================================================================
' Returns an string describing in English the error condition for the most recent
' sqlite3_* API call.
' ========================================================================================
FUNCTION SQL3_ErrMsg (BYVAL hSqlite AS DWORD) AS STRING
   LOCAL pErrMsg AS ASCIIZ PTR
   IF hSqlite = %NULL THEN EXIT FUNCTION
   pErrMsg = sqlite3_errmsg(hSqlite)
   FUNCTION = @pErrMsg
END FUNCTION
' ========================================================================================

' ========================================================================================
' Main
' ========================================================================================
FUNCTION PBMAIN () AS LONG

   LOCAL hr AS LONG
   LOCAL hLite AS DWORD
   LOCAL szDbName AS ASCIIZ * %MAX_PATH
   LOCAL szSQL AS ASCIIZ * 256
   LOCAL pTable AS DWORD PTR
   LOCAL cRows AS LONG
   LOCAL cCols AS LONG
   LOCAL pErrMsg AS ASCIIZ PTR

   ' Delete the database if already exists
   szDbName = $TEST_DATABASE
IF DIR$(szDbName) <> "" THEN
KILL szDbName
END IF

   ' Create the database
   hr = sqlite3_open(szDbName, hLite)
   IF hr <> %SQLITE_OK OR hLite = %NULL THEN
      PRINT "Error " & STR$(hr) & " creating the database"
      IF hLite THEN sqlite3_close(hLite)
      EXIT FUNCTION
   END IF

' Create a table
   szSQL = "CREATE TABLE Table1 (ID INT, Name TEXT, Age TEXT)"
   hr = sqlite3_get_table(hLite, szSQL, pTable, cRows, cCols, pErrMsg)
   IF hr <> %SQLITE_OK THEN
      PRINT @pErrMsg
      sqlite3_free(pErrMsg)
      GOTO Terminate
   END IF

   ' Discard the result set
   if pTable THEN sqlite3_free_table (pTable)

   PRINT "Database created"

Terminate:

   ' Close the database
   IF hLite THEN sqlite3_close(hLite)

   WAITKEY$

END FUNCTION
' ========================================================================================