Aggiunto supporto per Sqlite3.dll

git-svn-id: svn://10.65.10.50/branches/R_10_00@22986 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
guy 2014-07-30 13:01:24 +00:00
parent ee688476cc
commit eb2af57675
6 changed files with 132 additions and 54 deletions

View File

@ -26,6 +26,7 @@ static unsigned int aga_getziplist(const char* zipfile, wxArrayString& aFiles)
return aFiles.GetCount(); return aFiles.GetCount();
} }
/*
static int aga_find_slash(const wxString& path, int from) static int aga_find_slash(const wxString& path, int from)
{ {
for (int i = from; path[i]; i++) for (int i = from; path[i]; i++)
@ -34,25 +35,18 @@ static int aga_find_slash(const wxString& path, int from)
return -1; return -1;
} }
*/
static void aga_create_dir(wxString strPath) static bool aga_create_dir(wxString strPath)
{ {
if (!wxEndsWithPathSeparator(strPath)) bool ok = wxFileName::Mkdir(strPath, 0x777, wxPATH_MKDIR_FULL);
strPath += wxFILE_SEP_PATH; if (!ok)
for (int i = aga_find_slash(strPath, 0); i > 0; i = aga_find_slash(strPath, i+1))
{ {
const wxString strDir = strPath.Mid(0,i); wxString strMsg;
if (!::wxDirExists(strDir)) strMsg << "Impossibile creare la cartella " << strPath;
{ xvt_dm_post_error(strMsg);
if (!::wxMkdir(strDir))
{
wxString strMsg = "Impossibile creare la cartella ";
strMsg << strDir << " !!";
wxMessageBox(strMsg, "Attenzione!", wxICON_ERROR);
}
}
} }
return ok;
} }
bool aga_unzip(const char* zipfile, const char* destdir) bool aga_unzip(const char* zipfile, const char* destdir)

View File

@ -987,8 +987,9 @@ bool OsWin32_GotoUrl(const char* url, const char* action)
} else } else
if (wxStrstr(url, ".jar")) if (wxStrstr(url, ".jar"))
{ {
wxString args; args << "-jar " << url; const wxFileName fn = url;
HINSTANCE hinst = ::ShellExecute(NULL, NULL, "java.exe", args, NULL, SW_HIDE); // Hide java console wxString args; args << "-jar " << fn.GetFullName();
HINSTANCE hinst = ::ShellExecute(NULL, NULL, "java.exe", args, fn.GetPath(), SW_HIDE); // Hide java console
DWORD winst = DWORD((DWORD*)hinst); // Tutto 'sto giro per evitare un warning DWORD winst = DWORD((DWORD*)hinst); // Tutto 'sto giro per evitare un warning
ok = UINT(winst) > 32; ok = UINT(winst) > 32;
} }

View File

@ -1827,7 +1827,7 @@ SLIST xvt_fsys_list_files(const char *type, const char *pat, BOOLEAN dirs)
{ {
SLIST list = xvt_slist_create(); SLIST list = xvt_slist_create();
int flags = 0; int flags = wxFILE | wxDIR;
if (dirs) if (dirs)
{ {
if (strcmp(type, DIR_TYPE) == 0) if (strcmp(type, DIR_TYPE) == 0)
@ -1846,7 +1846,6 @@ SLIST xvt_fsys_list_files(const char *type, const char *pat, BOOLEAN dirs)
const wxString fnDir = fnPath.GetPath(wxPATH_GET_VOLUME, wxPATH_UNIX); const wxString fnDir = fnPath.GetPath(wxPATH_GET_VOLUME, wxPATH_UNIX);
const wxString fnName = fnPath.GetFullName(); const wxString fnName = fnPath.GetFullName();
const int mask = dirs ? (strcmp(type, DIR_TYPE) == 0 ? 2 : 3) : 1;
wxFTP ftp; wxFTP ftp;
if (!strUser.IsEmpty()) if (!strUser.IsEmpty())
@ -1867,14 +1866,12 @@ SLIST xvt_fsys_list_files(const char *type, const char *pat, BOOLEAN dirs)
for (size_t i = 0; i < files.GetCount(); i++) for (size_t i = 0; i < files.GetCount(); i++)
{ {
const int type = files[i][0] == 'd' ? 2 : 1; const int type = files[i][0] == 'd' ? wxDIR : wxFILE;
if (type & mask) if (type & flags) // Entry type matches desired mask?
{ {
wxString f(RemotePath); wxString f = RemotePath; f << '/' << files[i].AfterLast(' ');
f << '/' << files[i].AfterLast(' ');
wxString size = files[i].Mid(30); wxString size = files[i].Mid(30);
xvt_slist_add_at_elt(list, NULL, f, type == 2 ? -1 : wxAtol(size)); xvt_slist_add_at_elt(list, NULL, f, type == wxFILE ? wxAtol(size) : -1L);
} }
} }
} }
@ -3604,8 +3601,8 @@ long xvt_sys_get_profile_int(const char* file, const char* paragraph, const char
return value; return value;
} }
BOOLEAN xvt_sys_set_profile_string(const char* file, const char* paragraph, const char* name, BOOLEAN xvt_sys_set_profile_string(const char* file, const char* paragraph,
const char* value) const char* name, const char* value)
{ {
if (file == NULL || *file == '\0') if (file == NULL || *file == '\0')
file = xvt_fsys_get_campo_ini(); file = xvt_fsys_get_campo_ini();
@ -3613,29 +3610,14 @@ BOOLEAN xvt_sys_set_profile_string(const char* file, const char* paragraph, cons
if (paragraph == NULL || *paragraph == '\0') if (paragraph == NULL || *paragraph == '\0')
paragraph = "Main"; paragraph = "Main";
#ifdef __WXMSW__ return ::WritePrivateProfileString(paragraph, name, value, file) > 0;
return ::WritePrivateProfileString(paragraph, name, value, file);
#else
wxFileConfig ini("", "", file, "", wxCONFIG_USE_LOCAL_FILE | wxCONFIG_USE_RELATIVE_PATH);
ini.SetUmask(0x0);
wxString path;
path << "/" << paragraph;
ini.SetPath(path);
return ini.Write(name, value);
#endif
} }
BOOLEAN xvt_sys_find_editor(const char* file, char* editor) BOOLEAN xvt_sys_find_editor(const char* file, char* editor)
{ {
BOOLEAN ok = FALSE; BOOLEAN ok = FALSE;
#ifdef __WXMSW__
const wxString e = OsWin32_File2App(file); const wxString e = OsWin32_File2App(file);
#else
const wxString e = OsLinux_File2App(file);
#endif
ok = !e.IsEmpty(); ok = !e.IsEmpty();
if (ok && editor != NULL) if (ok && editor != NULL)
wxStrncpy(editor, e, _MAX_PATH); wxStrncpy(editor, e, _MAX_PATH);

View File

@ -495,12 +495,15 @@ XVTDLL BOOLEAN xvt_odbc_free_connection(XVT_ODBC handle);
XVTDLL ULONG xvt_odbc_execute(XVT_ODBC handle, const char* sql, ODBC_CALLBACK cb, void* jolly); XVTDLL ULONG xvt_odbc_execute(XVT_ODBC handle, const char* sql, ODBC_CALLBACK cb, void* jolly);
XVTDLL BOOLEAN xvt_odbc_driver(XVT_ODBC handle, char* str, int max_size); XVTDLL BOOLEAN xvt_odbc_driver(XVT_ODBC handle, char* str, int max_size);
XVTDLL BOOLEAN xvt_sql_begin(XVT_SQLDB handle);
XVTDLL BOOLEAN xvt_sql_close(XVT_SQLDB handle); XVTDLL BOOLEAN xvt_sql_close(XVT_SQLDB handle);
XVTDLL BOOLEAN xvt_sql_commit(XVT_SQLDB handle);
XVTDLL BOOLEAN xvt_sql_driver(XVT_SQLDB handle, char* str, int max_size); XVTDLL BOOLEAN xvt_sql_driver(XVT_SQLDB handle, char* str, int max_size);
XVTDLL ULONG xvt_sql_execute(XVT_SQLDB handle, const char* sql, ODBC_CALLBACK cb, void* jolly); XVTDLL ULONG xvt_sql_execute(XVT_SQLDB handle, const char* sql, ODBC_CALLBACK cb, void* jolly);
XVTDLL SLIST xvt_sql_list_fields(XVT_SQLDB handle, const char* table); XVTDLL SLIST xvt_sql_list_fields(XVT_SQLDB handle, const char* table);
XVTDLL SLIST xvt_sql_list_tables(XVT_SQLDB handle); XVTDLL SLIST xvt_sql_list_tables(XVT_SQLDB handle);
XVTDLL XVT_SQLDB xvt_sql_open(const char* dsn, const char* usr, const char* pwd, const char* dir); XVTDLL XVT_SQLDB xvt_sql_open(const char* dsn, const char* usr, const char* pwd, const char* dir);
XVTDLL BOOLEAN xvt_sql_rollback(XVT_SQLDB handle);
XVTDLL BOOLEAN xvt_sql_table_exists(XVT_SQLDB handle, const char* name); XVTDLL BOOLEAN xvt_sql_table_exists(XVT_SQLDB handle, const char* name);

View File

@ -14,6 +14,10 @@ public:
virtual SLIST ListTables() const = 0; virtual SLIST ListTables() const = 0;
virtual bool TableExists(const char* name) const; virtual bool TableExists(const char* name) const;
virtual bool Begin() const { return false; }
virtual bool Commit() const { return false; }
virtual bool Rollback() const { return false; }
virtual ~XVT_SQLDataBase() { Close(); } virtual ~XVT_SQLDataBase() { Close(); }
}; };
@ -45,6 +49,10 @@ protected:
virtual bool TableExists(const char* name) const; virtual bool TableExists(const char* name) const;
public: public:
virtual bool Begin() const;
virtual bool Commit() const;
virtual bool Rollback() const;
XVT_SQLDB_SQLite3() : m_pDB(NULL) {} XVT_SQLDB_SQLite3() : m_pDB(NULL) {}
}; };
@ -77,6 +85,51 @@ bool XVT_SQLDB_SQLite3::Close()
return true; return true;
} }
bool XVT_SQLDB_SQLite3::Begin() const
{
bool bDone = IsOk();
if (bDone)
{
try { m_pDB->Begin(); }
catch(wxSQLite3Exception& e)
{
xvt_dm_post_error(e.GetMessage());
bDone = false;
}
}
return bDone;
}
bool XVT_SQLDB_SQLite3::Commit() const
{
bool bDone = IsOk();
if (bDone)
{
try { m_pDB->Commit(); }
catch(wxSQLite3Exception& e)
{
xvt_dm_post_error(e.GetMessage());
bDone = false;
}
}
return bDone;
}
bool XVT_SQLDB_SQLite3::Rollback() const
{
bool bDone = IsOk();
if (bDone)
{
try { m_pDB->Rollback(); }
catch(wxSQLite3Exception& e)
{
xvt_dm_post_error(e.GetMessage());
bDone = false;
}
}
return bDone;
}
ULONG XVT_SQLDB_SQLite3::Execute(const char* sql, ODBC_CALLBACK cb, void* jolly) ULONG XVT_SQLDB_SQLite3::Execute(const char* sql, ODBC_CALLBACK cb, void* jolly)
{ {
ULONG nRows = 0; ULONG nRows = 0;
@ -88,20 +141,27 @@ ULONG XVT_SQLDB_SQLite3::Execute(const char* sql, ODBC_CALLBACK cb, void* jolly)
try try
{ {
wxSQLite3ResultSet rs = m_pDB->ExecuteQuery(sql); wxSQLite3ResultSet rs = m_pDB->ExecuteQuery(sql);
const short numcols = rs.GetColumnCount(); short numcols = rs.GetColumnCount();
if (numcols > 0) if (numcols > 0)
{ {
char** values = new char*[numcols]; // Lista dei valori del record corrente wxArrayString aNames, aValues;
memset(values, 0, numcols*sizeof(char*));
const short nMaxCols = 256;
char* values[nMaxCols]; // Lista dei valori del record corrente
memset(values, 0, sizeof(values));
char** names = new char*[numcols*2]; // Lista dei nomi dei campi e dei tipi char* names[2*nMaxCols]; // Lista dei nomi dei campi e dei tipi
memset(names, 0, numcols*2*sizeof(char*)); memset(names, 0, sizeof(names));
if (numcols > nMaxCols)
numcols = nMaxCols;
short c; short c;
for (c = 0; c < numcols; c++) for (c = 0; c < numcols; c++)
{ {
names[c] = (char*)(const char*)rs.GetColumnName(c); aNames.Add(rs.GetColumnName(c));
names[c] = (char*)(const char*)aNames[c];
switch (rs.GetColumnType(c)) switch (rs.GetColumnType(c))
{ {
case WXSQLITE_INTEGER: case WXSQLITE_INTEGER:
@ -114,15 +174,16 @@ ULONG XVT_SQLDB_SQLite3::Execute(const char* sql, ODBC_CALLBACK cb, void* jolly)
while (rs.NextRow()) while (rs.NextRow())
{ {
aValues.Empty();
for (c = 0; c < numcols; c++) for (c = 0; c < numcols; c++)
values[c] = (char*)(const char*)rs.GetAsString(c); {
aValues.Add(rs.GetAsString(c));
values[c] = (char*)(const char*)aValues[c];
}
if (cb(jolly, numcols, values, names) != 0) if (cb(jolly, numcols, values, names) != 0)
break; break;
nRows++; nRows++;
} }
delete values; // butta la lista dei valori
delete names; // butta la lista dei nomi
} }
} }
catch(wxSQLite3Exception& e) catch(wxSQLite3Exception& e)
@ -212,6 +273,42 @@ BOOLEAN xvt_sql_close(XVT_SQLDB handle)
return ok; return ok;
} }
BOOLEAN xvt_sql_begin(XVT_SQLDB handle)
{
BOOLEAN ok = handle != NULL;
if (ok)
{
XVT_SQLDataBase* db = (XVT_SQLDataBase*)handle;
if (db != NULL)
ok = db->Begin();
}
return ok;
}
BOOLEAN xvt_sql_commit(XVT_SQLDB handle)
{
BOOLEAN ok = handle != NULL;
if (ok)
{
XVT_SQLDataBase* db = (XVT_SQLDataBase*)handle;
if (db != NULL)
ok = db->Commit();
}
return ok;
}
BOOLEAN xvt_sql_rollback(XVT_SQLDB handle)
{
BOOLEAN ok = handle != NULL;
if (ok)
{
XVT_SQLDataBase* db = (XVT_SQLDataBase*)handle;
if (db != NULL)
ok = db->Rollback();
}
return ok;
}
ULONG xvt_sql_execute(XVT_SQLDB handle, const char* sql, ODBC_CALLBACK cb, void* jolly) ULONG xvt_sql_execute(XVT_SQLDB handle, const char* sql, ODBC_CALLBACK cb, void* jolly)
{ {
ULONG n = 0; ULONG n = 0;

View File

@ -111,10 +111,11 @@ XVT_POPUP_OVER_ITEM
} XVT_POPUP_ALIGNMENT; } XVT_POPUP_ALIGNMENT;
#define SZ_FNAME _MAX_FNAME #define SZ_FNAME _MAX_FNAME
#define SZ_EXT 6
typedef struct { /* file specification */ typedef struct { /* file specification */
DIRECTORY dir; /* directory */ DIRECTORY dir; /* directory */
char type[6]; /* file type/extension */ char type[SZ_EXT]; /* file type/extension */
char name[SZ_FNAME]; /* filename */ char name[SZ_FNAME]; /* filename */
char creator[6]; /* file creator */ char creator[6]; /* file creator */
} FILE_SPEC; } FILE_SPEC;