Return to Snippet

Revision: 65170
at November 3, 2013 15:25 by ktrout


Initial Code
#include <sqlite3.h>
#include <stdio.h>

#define safe_exit() sqlite3_close(db);db=0;return 0
#define _tempdb "temp.db"

int error;

int main()
{
	sqlite3 *db; char sql[300]; char *err_msg;
	error = sqlite3_open(_tempdb, &db);
	if(error!=SQLITE_OK)
	{
		safe_exit();
	}
	error = sqlite3_exec(db, "CREATE TABLE IF NOT EXISTS \"memory\" (\"order\" INTEGER PRIMARY KEY,\"address\" INTEGER,\"size\" INTEGER,\"file\" TEXT NOT NULL,\"line\" INTEGER,\"typ\" INTEGER);", 0, 0, 0);
	if(error!=SQLITE_OK)
	{
		safe_exit();
	}
	sprintf(sql,"INSERT INTO \"memory\" (\"address\",\"size\",\"file\",\"line\",\"typ\") VALUES (1442040,20,'fname',22,1);");
	error = sqlite3_exec(db, sql, 0, 0, &err_msg);
	if(error!=SQLITE_OK)
	{
		fprintf(stdout,"error: %s\n",err_msg);
	}
	safe_exit();
}

Initial URL


Initial Description
Source creating a new database (and inserting some records)

Initial Title
sqlite create new table

Initial Tags
table

Initial Language
C