SQLite 메모리 데이터베이스 단순 사용 사례

#include <stdio.h>
#include <stdlib.h>
#include<string.h>
#include "sqlite3.h"
#pragma comment(lib,"sqlite3.lib")
#include <windows.h>
#include <iostream>
#include "CodingConv.h"
int main(int argc, char* argv[])
{
	int rc,i,ncols;	
	sqlite3 *db;
	sqlite3_stmt *stmt;
	char *sql;
	const char *tail;
	char* zErrMsg;
	rc=sqlite3_open(":memory:",&db);
	rc=sqlite3_exec(db,"attach 'c:\\mydatabase.db' as new_Db",0,0,&zErrMsg);
	sqlite3_exec(db,"detach 'C:\\mydatabase.db",0,0,&zErrMsg);
	//char temp[256]="c:\\   \\mydatabase.db";
	//char FileRoot[256];
	//CCodingConv::GB2312_2_UTF8(FileRoot,256,temp,0);
	//
	//rc=sqlite3_open(FileRoot,&db);
    //rc = sqlite3_open("mydatabase.db", &db);
    if(rc!= SQLITE_OK )		
    {		
		printf("failed to open database!
"); return -1; } sql="select * from test"; rc=sqlite3_prepare(db,sql,(int)strlen(sql),&stmt,&tail); if(rc!=SQLITE_OK) { fprintf(stderr,"SQL error:%sn",sqlite3_errmsg(db)); } rc=sqlite3_step(stmt); ncols=sqlite3_column_count(stmt); while(rc==SQLITE_ROW) { for(i=0;i<ncols;i++) { fprintf(stderr,"%s",sqlite3_column_text(stmt,i)); } fprintf(stderr,"
"); rc=sqlite3_step(stmt); } sqlite3_finalize(stmt); sqlite3_close(db); printf("
"); return 0; }

좋은 웹페이지 즐겨찾기