// **************************************************************************** // copyright (c) 2000-2005 Horst Knorr // This file is part of the hk_sqliteclasses 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" hk_sqliteconnection::hk_sqliteconnection(hk_drivermanager* c):hk_connection(c) { #ifdef HK_DEBUG hkdebug("hk_sqliteconnection::hk_sqliteconnection"); #endif /*p_SQL_Connection=NULL; set_tcp_port(default_tcp_port());*/ } hk_sqliteconnection::~hk_sqliteconnection() { #ifdef HK_DEBUG hkdebug("hk_sqliteconnection::~hk_sqliteconnection"); #endif } bool hk_sqliteconnection::driver_specific_connect() { #ifdef HK_DEBUG hkdebug("hk_sqliteconnection::driver_specific_connect"); #endif p_connected=true; return true; } bool hk_sqliteconnection::driver_specific_disconnect() { #ifdef HK_DEBUG hkdebug("hk_sqliteconnection::driver_specific_disconnect"); #endif return true; } vector* hk_sqliteconnection::driver_specific_dblist(void) { #ifdef HK_DEBUG hkdebug("hk_sqliteconnection::driver_specific_dblist"); #endif DIR *dp; struct dirent *entry; hk_string datei; hk_string fileend=".hk_sqlite"; 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_sqlite"); ifstream ifs(n.c_str(),ios::in); if (ifs) { //servermessage(hk_translate("Database already exists")); return false; } sqlite* p_sqlitehandler=sqlite_open(n.c_str(),0,&errormsg); if (!p_sqlitehandler && errormsg) { servermessage(errormsg); sqlite_freemem(errormsg); errormsg=0; return false; } sqlite_close(p_sqlitehandler); hk_database* db=driver_specific_new_database(); if (db) {db->set_name(dbase); db->create_centralstoragetable(); delete db; } return true; } bool hk_sqliteconnection::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_sqlite"; int r=unlink(filename.c_str()); return r==0; } //*********************************************************** hk_connection* create_connection(hk_drivermanager* cl) { return new hk_sqliteconnection(cl); } hk_string hk_classesversion(void) { return (hk_string)HK_VERSION; }