[o2on-svn] [66] Firebird対応 :create_table, コンストラクタ

Back to archive index

o2on svn commit o2on-****@lists*****
2008年 3月 26日 (水) 01:22:29 JST


Revision: 66
          http://svn.sourceforge.jp/cgi-bin/viewcvs.cgi?root=o2on&view=rev&rev=66
Author:   k-uehara
Date:     2008-03-26 01:22:29 +0900 (Wed, 26 Mar 2008)

Log Message:
-----------
Firebird対応:create_table, コンストラクタ

Modified Paths:
--------------
    trunk/o2on/src.o2on/O2DatDB.cpp
    trunk/o2on/src.o2on/O2DatDB.h

Modified: trunk/o2on/src.o2on/O2DatDB.cpp
===================================================================
--- trunk/o2on/src.o2on/O2DatDB.cpp	2008-03-23 12:03:15 UTC (rev 65)
+++ trunk/o2on/src.o2on/O2DatDB.cpp	2008-03-25 16:22:29 UTC (rev 66)
@@ -46,6 +46,24 @@
 	, UpdateThreadHandle(NULL)
 	, UpdateThreadLoop(false)
 {
+#ifdef O2_DB_FIREBIRD
+	FromUnicode(L"shift_jis", filename, dbfilenameA);
+
+	char user_name[] = "SYSDBA";
+	char user_password[] = "masterkey";
+	char *dpb, *p;
+	dpb = dpb_buff;
+	*dpb++ = isc_dpb_version1;
+	*dpb++ = isc_dpb_user_name;
+	*dpb++ = strlen(user_name);
+	for (p = user_name; *p;)
+		*dpb++ = *p++;
+	*dpb++ = isc_dpb_password;
+	*dpb++ = strlen(user_password);
+	for (p = user_password; *p;)
+		*dpb++ = *p++;
+	dpblen = dpb - dpb_buff;
+#endif
 }
 
 
@@ -64,7 +82,8 @@
 {
 	string errmsg;
 	char msg[512];
-	while(isc_interprete(msg, (ISC_STATUS **)&status)){
+	const ISC_STATUS* st = status;
+	while(fb_interpret(msg, sizeof(msg), &st)){
 		errmsg += msg;
 		errmsg += " ";
     }
@@ -199,8 +218,51 @@
 	stopwatch sw("create table/index and analyze");
 #endif
 #ifdef O2_DB_FIREBIRD
+	isc_db_handle db = NULL;
+	isc_tr_handle tr = NULL;
+	isc_stmt_handle stmt = NULL;
+	ISC_STATUS_ARRAY status;
+
+	char create_db[512];
+	sprintf_s(create_db, 512, "CREATE DATABASE '%s' USER 'SYSDBA' PASSWORD 'masterkey';", dbfilenameA.c_str());
+	if (!isc_dsql_execute_immediate(status, &db, &tr, 0, create_db, 1, NULL))
+		isc_detach_database(status, &db);
+	
+	if (isc_attach_database(status, 0, dbfilenameA.c_str(), &db, dpblen, dpb_buff))
+		goto error;
+
+	char *sql = 
+		"EXECUTE BLOCK AS BEGIN "
+		"if (not exists(select 1 from rdb$relations where rdb$relation_name = 'DAT')) then "
+		"execute statement 'create table DAT ("
+		"    hash         CHAR(20) NOT NULL PRIMARY KEY,"//length is HASHSIZE in sha.h
+		"    domainname   VARCHAR(10),"
+		"    datname      VARCHAR(20),"
+		"    filesize     INTEGER,"
+		"    disksize     INTEGER,"
+		"    url          VARCHAR(128),"
+		"    title        VARCHAR(256),"
+		"    res          INTEGER,"
+		"    lastupdate   INTEGER,"
+		"    lastpublish  INTEGER"
+		");';"
+		"END";
+
+	if (isc_start_transaction(status, &tr, 1, &db, 0, NULL))
+		goto error;
+	if (isc_dsql_execute_immediate(status, &db, &tr, 0, sql, 1, NULL))
+		goto error;
+	if (isc_commit_transaction(status, &tr))
+		goto error;
+	if (isc_detach_database(status, &db))
+		goto error;
+	return true;
+
+error:
+	log(status);
+	if (tr) isc_rollback_transaction(status, &tr);
+	if (db) isc_detach_database(status, &db);
 	return false;
-
 #else
 	sqlite3 *db = NULL;
 	int err = sqlite3_open16(dbfilename.c_str(), &db);

Modified: trunk/o2on/src.o2on/O2DatDB.h
===================================================================
--- trunk/o2on/src.o2on/O2DatDB.h	2008-03-23 12:03:15 UTC (rev 65)
+++ trunk/o2on/src.o2on/O2DatDB.h	2008-03-25 16:22:29 UTC (rev 66)
@@ -60,6 +60,9 @@
 protected:
 	O2Logger		*Logger;
 	wstring			dbfilename;
+	string			dbfilenameA;
+	ISC_SCHAR		dpb_buff[128];
+	short			dpblen;
 
 	O2DatRecList	UpdateQueue;
 	Mutex			UpdateQueueLock;
@@ -69,13 +72,14 @@
 protected:
 #ifdef O2_DB_FIREBIRD
 	void log(ISC_STATUS_ARRAY &status);
-	//bool bind(sqlite3 *db, sqlite3_stmt* stmt, int index, const uint64 num);
-	//bool bind(sqlite3 *db, sqlite3_stmt* stmt, int index, const wchar_t *str);
-	//bool bind(sqlite3 *db, sqlite3_stmt* stmt, int index, const wstring &str);
-	//bool bind(sqlite3 *db, sqlite3_stmt* stmt, int index, const hashT &hash);
-	//void get_columns(sqlite3_stmt* stmt, O2DatRec &rec);
-	//void get_columns(sqlite3_stmt* stmt, wstrarray &cols);
-	//void get_column_names(sqlite3_stmt* stmt, wstrarray &cols);
+	bool bind(sqlite3 *db, sqlite3_stmt* stmt, int index, const uint64 num);
+	bool bind(sqlite3 *db, sqlite3_stmt* stmt, int index, const wchar_t *str);
+	bool bind(sqlite3 *db, sqlite3_stmt* stmt, int index, const wstring &str);
+	bool bind(sqlite3 *db, sqlite3_stmt* stmt, int index, const hashT &hash);
+	void get_columns(sqlite3_stmt* stmt, O2DatRec &rec);
+	void get_columns(sqlite3_stmt* stmt, wstrarray &cols);
+	void get_column_names(sqlite3_stmt* stmt, wstrarray &cols);
+	void log(sqlite3 *db);
 #else
 	void log(sqlite3 *db);
 	bool bind(sqlite3 *db, sqlite3_stmt* stmt, int index, const uint64 num);
@@ -91,7 +95,30 @@
 	O2DatDB(O2Logger *lgr, const wchar_t *filename);
 	~O2DatDB();
 
+#ifdef O2_DB_FIREBIRD
 	bool create_table(void);
+	//bool reindex(const char *target);
+
+	//size_t select(const wchar_t *sql, SQLResultList &out);
+	//bool select(O2DatRec &out);
+	//bool select(O2DatRec &out, const hashT hash);
+	//bool select(O2DatRec &out, const wchar_t *domain, const wchar_t *bbsname);
+	//bool select(O2DatRecList &out);
+	//bool select(O2DatRecList &out, const wchar_t *domain, const wchar_t *bbsname);
+	//bool select(O2DatRec &out, const wchar_t *domain, const wchar_t *bbsname, const wchar_t *datname);
+	//bool select(O2DatRecList &out, time_t publish_tt, size_t limit);
+	//uint64 select_datcount(void);
+	//uint64 select_datcount(wstrnummap &out);
+	//uint64 select_totaldisksize(void);
+	//uint64 select_publishcount(time_t publish_tt);
+
+//	bool update(O2DatRec &in, bool is_origurl);
+	//void update(O2DatRecList &in);
+//	bool update_lastpublish(const hashT &hash);
+
+	//bool remove(const hashT &hash);
+#else
+	bool create_table(void);
 	bool reindex(const char *target);
 
 	size_t select(const wchar_t *sql, SQLResultList &out);
@@ -112,6 +139,7 @@
 //	bool update_lastpublish(const hashT &hash);
 
 	bool remove(const hashT &hash);
+#endif
 
 	void AddUpdateQueue(O2DatRec &in);
 	void AddUpdateQueue(const hashT &hash);




o2on-svn メーリングリストの案内
Back to archive index