#include "app.h"
/****************************************************************************
 *	
 ****************************************************************************/
static void test();
/****************************************************************************
 *	main
 ****************************************************************************/
int main(int argc, char* argv[]) {
	putenv("GC_LOG_FILE=CON");//ログ出力先を指定する。
	GC_set_find_leak(1);//メモリリーク検出を開始する。
	test();
	CHECK_LEAKS();//メモリリークを検出する。
	cputs("ok");
	getch();
	return EXIT_SUCCESS;
}
/****************************************************************************
 *	test
 ****************************************************************************/
static void test() {
	int rc, iCol;
	sqlite* db = sqlite_open(":memory:", 0, NULL);
	rc = sqlite_exec_printf(db, "CREATE TABLE tbl(id INTEGER PRIMARY KEY, val)", NULL, NULL, NULL);
	if(rc) { DIE(); }
	rc = sqlite_exec_printf(db, "BEGIN", NULL, NULL, NULL);
	if(rc) { DIE(); }
	{
		ST_Recordset_w* rs_w;
		rs_w = Recordset_New(db, "tbl");
			Recordset_SetNN(rs_w, 1234			,"id");
			Recordset_SetNT(rs_w, "One-Two-Three-Four"	,"val");
		Recordset_Insert(rs_w);
		rs_w = Recordset_New(db, "tbl");
			Recordset_SetNN(rs_w, 56			,"id");
			Recordset_SetNT(rs_w, "Five-Six"		,"val");
		Recordset_Insert(rs_w);
		rs_w = Recordset_New(db, "tbl");
			Recordset_SetNN(rs_w, 789			,"id");
			Recordset_SetNT(rs_w, "Seven-Eight-Nine"	,"val");
		Recordset_Insert(rs_w);
		rs_w = Recordset_New(db, "tbl");
			Recordset_SetNT(rs_w, "FIVE-SIX"		,"val");
		Recordset_Update(rs_w, "id = 56");
	}
	rc = sqlite_exec_printf(db, "COMMIT", NULL, NULL, NULL);
	if(rc) { DIE(); }
	{
		ST_Recordset_r* rs_r;
		for(rs_r = Recordset_Open(db, "SELECT * FROM %s ORDER BY id", "tbl");
		    rs_r;
		    rs_r = Recordset_Next(rs_r)) {
			for(iCol = 0; iCol < Recordset_Count(rs_r); iCol++) {
				if(iCol) { putchar(','); }
				printf("%s=%s",
					Recordset_ColIN(rs_r, iCol),
					Recordset_GetIT(rs_r, iCol));
			}
			putchar('\n');
		}
	}
	sqlite_close(db);
}
