SQLite

SQLite

CategoryRelational database
LicensePublic domain
Websitehttps://sqlite.org/

SQLite is a relational database management system which is embedded into the end program.

Data type

INTEGERInteger 64bit
REALFloating point 64bit
TEXTVariable-length string (UTF-8/16)
BLOBVariable-length binary data

SQL sample code

-- Concat strings.
SELECT 'Hello,' || 'world';

-- Append "" to the identifier to distinguish from reserved words.
SELECT "IN" FROM "WHERE";

-- If specified record exists then insert, nor append. (PRIMARY KEY required)
REPLACE INTO page (title,contents) VALUES(?,?);

Sample code on C

#include <stdio.h>
#include <stdlib.h>
#include <sqlite3.h>


int main(int argc,char **argv)
{
  sqlite3 *db;
  if (sqlite3_open("test.db", &db) != SQLITE_OK){
    fprintf(stderr, "cannot open test.db\n");
    exit(1);
  }

  sqlite3_stmt *st;
  if (sqlite3_prepare_v2(db, "SELECT name FROM book WHERE price>?", -1, &st, NULL) != SQLITE_OK) {
    fprintf(stderr, "%s\n", sqlite3_errmsg(db));
    exit(1);
  }

  // Set first place holder to 100
  sqlite3_bind_int(st, 0, 100);

  while (sqlite3_step(st) == SQLITE_ROW) {
    printf("%s\n", sqlite3_column_text(st, 0));
  }
  sqlite3_finalize(st);
  sqlite3_close(db);

  return 0;
}