// **************************************************************************** // copyright (c) 2000-2005 Horst Knorr // This file is part of the hk_sqlite3classes library. // This file may be distributed and/or modified under the terms of the // GNU Library Public License version 2 as published by the Free Software // Foundation and appearing in the file COPYING included in the // packaging of this file. // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. // **************************************************************************** #include #include #include #include #include #include #include "hk_drivermanager.h" #include "hk_actionquery.h" #include "hk_url.h" #ifndef SQLITE_VERSION_NUMBER #define SQLITE_VERSION_NUMBER 0 #endif hk_sqlite3connection::hk_sqlite3connection(hk_drivermanager* c):hk_connection(c) { #ifdef HK_DEBUG hkdebug("hk_sqlite3connection::hk_sqlite3connection"); #endif /*p_SQL_Connection=NULL; set_tcp_port(default_tcp_port());*/ } hk_sqlite3connection::~hk_sqlite3connection() { #ifdef HK_DEBUG hkdebug("hk_sqlite3connection::~hk_sqlite3connection"); #endif } bool hk_sqlite3connection::driver_specific_connect() { #ifdef HK_DEBUG hkdebug("hk_sqlite3connection::driver_specific_connect"); #endif p_connected=true; return true; } bool hk_sqlite3connection::driver_specific_disconnect() { #ifdef HK_DEBUG hkdebug("hk_sqlite3connection::driver_specific_disconnect"); #endif return true; } vector* hk_sqlite3connection::driver_specific_dblist(void) { #ifdef HK_DEBUG hkdebug("hk_sqlite3connection::driver_specific_dblist"); #endif DIR *dp; struct dirent *entry; hk_string datei; hk_string fileend=".hk_sqlite3"; p_databaselist.erase(p_databaselist.begin(),p_databaselist.end()); if ((dp=opendir(databasepath().c_str()))!=NULL) { while ((entry = readdir(dp))!=NULL) { datei=entry->d_name; hk_string fname=databasepath()+"/"+datei; struct stat statbuf; stat(fname.c_str(),&statbuf); if (S_ISREG(statbuf.st_mode)) { size_t p =datei.find(fileend); if (p0?dbase:databasepath()+"/"+dbase+".hk_sqlite3"); ifstream ifs(n.c_str(),ios::in); if (ifs) { //servermessage(hk_translate("Database already exists")); return false; } sqlite3* p_sqlitehandler; if (sqlite3_open(n.c_str(),&p_sqlitehandler)) { servermessage(sqlite3_errmsg(p_sqlitehandler)); return false; } sqlite3_close(p_sqlitehandler); hk_database* db=driver_specific_new_database(); if (db && database_exists(dbase)) {db->set_name(dbase); db->create_centralstoragetable(); delete db; return true; } else return false; } bool hk_sqlite3connection::delete_database(const hk_string& dbase,enum_interaction c) { hk_string warning=hk_translate("Delete the database \"%DBNAME%\"?"); warning=replace_all("%DBNAME%",warning,dbase); if(c==interactive && !show_yesnodialog(warning,true)) return false; hk_url url=dbase; hk_string filename=url.directory().size()>0?dbase:databasepath()+"/"+dbase+".hk_sqlite3"; int r=unlink(filename.c_str()); return r==0; } //*********************************************************** hk_connection* create_connection(hk_drivermanager* cl) { return new hk_sqlite3connection(cl); } hk_string hk_classesversion(void) { return (hk_string)HK_VERSION; }