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:
		
							parent
							
								
									ee688476cc
								
							
						
					
					
						commit
						eb2af57675
					
				@ -26,6 +26,7 @@ static unsigned int aga_getziplist(const char* zipfile, wxArrayString& aFiles)
 | 
			
		||||
	return aFiles.GetCount();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
static int aga_find_slash(const wxString& path, int from)
 | 
			
		||||
{
 | 
			
		||||
  for (int i = from; path[i]; i++)
 | 
			
		||||
@ -34,25 +35,18 @@ static int aga_find_slash(const wxString& path, int from)
 | 
			
		||||
 | 
			
		||||
    return -1;
 | 
			
		||||
}
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
static void aga_create_dir(wxString strPath)
 | 
			
		||||
static bool aga_create_dir(wxString strPath)
 | 
			
		||||
{
 | 
			
		||||
  if (!wxEndsWithPathSeparator(strPath))
 | 
			
		||||
		strPath += wxFILE_SEP_PATH;
 | 
			
		||||
 | 
			
		||||
  for (int i = aga_find_slash(strPath, 0); i > 0; i = aga_find_slash(strPath, i+1))
 | 
			
		||||
  bool ok = wxFileName::Mkdir(strPath, 0x777,  wxPATH_MKDIR_FULL);
 | 
			
		||||
  if (!ok)
 | 
			
		||||
  {
 | 
			
		||||
    const wxString strDir = strPath.Mid(0,i);
 | 
			
		||||
	  if (!::wxDirExists(strDir))
 | 
			
		||||
    {
 | 
			
		||||
      if (!::wxMkdir(strDir))
 | 
			
		||||
      {
 | 
			
		||||
        wxString strMsg = "Impossibile creare la cartella ";
 | 
			
		||||
        strMsg << strDir << " !!";
 | 
			
		||||
        wxMessageBox(strMsg, "Attenzione!", wxICON_ERROR);
 | 
			
		||||
      }
 | 
			
		||||
    }			
 | 
			
		||||
    wxString strMsg;
 | 
			
		||||
    strMsg << "Impossibile creare la cartella " << strPath;
 | 
			
		||||
    xvt_dm_post_error(strMsg);
 | 
			
		||||
  }
 | 
			
		||||
  return ok;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool aga_unzip(const char* zipfile, const char* destdir)
 | 
			
		||||
 | 
			
		||||
@ -987,8 +987,9 @@ bool OsWin32_GotoUrl(const char* url, const char* action)
 | 
			
		||||
  } else
 | 
			
		||||
  if (wxStrstr(url, ".jar"))
 | 
			
		||||
  {
 | 
			
		||||
    wxString args; args << "-jar " << url;
 | 
			
		||||
    HINSTANCE hinst = ::ShellExecute(NULL, NULL, "java.exe", args, NULL, SW_HIDE); // Hide java console
 | 
			
		||||
    const wxFileName fn = url;
 | 
			
		||||
    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
 | 
			
		||||
    ok = UINT(winst) > 32; 
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@ -1827,7 +1827,7 @@ SLIST xvt_fsys_list_files(const char *type, const char *pat, BOOLEAN dirs)
 | 
			
		||||
{
 | 
			
		||||
	SLIST list = xvt_slist_create();
 | 
			
		||||
 | 
			
		||||
  int flags = 0;
 | 
			
		||||
  int flags = wxFILE | wxDIR;
 | 
			
		||||
	if (dirs)
 | 
			
		||||
	{
 | 
			
		||||
		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 fnName = fnPath.GetFullName();
 | 
			
		||||
		
 | 
			
		||||
		const int mask = dirs ? (strcmp(type, DIR_TYPE) == 0 ? 2 : 3) : 1;
 | 
			
		||||
    wxFTP ftp;
 | 
			
		||||
 | 
			
		||||
    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++)
 | 
			
		||||
			{
 | 
			
		||||
				const int type = files[i][0] == 'd' ? 2 : 1;			
 | 
			
		||||
				if (type & mask)
 | 
			
		||||
				const int type = files[i][0] == 'd' ? wxDIR : wxFILE;
 | 
			
		||||
				if (type & flags) // Entry type matches desired mask?
 | 
			
		||||
				{
 | 
			
		||||
					wxString f(RemotePath);
 | 
			
		||||
						
 | 
			
		||||
					f << '/' << files[i].AfterLast(' ');
 | 
			
		||||
					wxString f = RemotePath; f << '/' << files[i].AfterLast(' ');
 | 
			
		||||
					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;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
BOOLEAN xvt_sys_set_profile_string(const char* file, const char* paragraph, const char* name,
 | 
			
		||||
                                   const char* value)
 | 
			
		||||
BOOLEAN xvt_sys_set_profile_string(const char* file, const char* paragraph, 
 | 
			
		||||
                                   const char* name, const char* value)
 | 
			
		||||
{
 | 
			
		||||
  if (file == NULL || *file == '\0')
 | 
			
		||||
    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')
 | 
			
		||||
    paragraph = "Main";
 | 
			
		||||
 | 
			
		||||
#ifdef __WXMSW__
 | 
			
		||||
  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
 | 
			
		||||
  return ::WritePrivateProfileString(paragraph, name, value, file) > 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
BOOLEAN xvt_sys_find_editor(const char* file, char* editor)
 | 
			
		||||
{
 | 
			
		||||
  BOOLEAN ok = FALSE;
 | 
			
		||||
 | 
			
		||||
#ifdef __WXMSW__
 | 
			
		||||
  const wxString e = OsWin32_File2App(file);
 | 
			
		||||
#else
 | 
			
		||||
  const wxString e = OsLinux_File2App(file);
 | 
			
		||||
#endif
 | 
			
		||||
  ok = !e.IsEmpty();
 | 
			
		||||
  if (ok && editor != NULL)
 | 
			
		||||
    wxStrncpy(editor, e, _MAX_PATH);
 | 
			
		||||
 | 
			
		||||
@ -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 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_commit(XVT_SQLDB handle);
 | 
			
		||||
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 SLIST     xvt_sql_list_fields(XVT_SQLDB handle, const char* table);
 | 
			
		||||
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 BOOLEAN   xvt_sql_rollback(XVT_SQLDB handle);
 | 
			
		||||
XVTDLL BOOLEAN   xvt_sql_table_exists(XVT_SQLDB handle, const char* name);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -14,6 +14,10 @@ public:
 | 
			
		||||
  virtual SLIST ListTables() const = 0;
 | 
			
		||||
  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(); }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
@ -45,6 +49,10 @@ protected:
 | 
			
		||||
  virtual bool TableExists(const char* name) const;
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
  virtual bool Begin() const;
 | 
			
		||||
  virtual bool Commit() const;
 | 
			
		||||
  virtual bool Rollback() const;
 | 
			
		||||
 | 
			
		||||
  XVT_SQLDB_SQLite3() : m_pDB(NULL) {}
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
@ -77,6 +85,51 @@ bool XVT_SQLDB_SQLite3::Close()
 | 
			
		||||
  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 nRows = 0;
 | 
			
		||||
@ -88,20 +141,27 @@ ULONG XVT_SQLDB_SQLite3::Execute(const char* sql, ODBC_CALLBACK cb, void* jolly)
 | 
			
		||||
    try
 | 
			
		||||
    {
 | 
			
		||||
      wxSQLite3ResultSet rs = m_pDB->ExecuteQuery(sql);
 | 
			
		||||
      const short numcols = rs.GetColumnCount();
 | 
			
		||||
      short numcols = rs.GetColumnCount();
 | 
			
		||||
 | 
			
		||||
      if (numcols > 0)
 | 
			
		||||
      {
 | 
			
		||||
        char** values = new char*[numcols];  // Lista dei valori del record corrente 
 | 
			
		||||
        memset(values, 0, numcols*sizeof(char*));
 | 
			
		||||
        wxArrayString aNames, aValues;
 | 
			
		||||
 | 
			
		||||
        char** names = new char*[numcols*2]; // Lista dei nomi dei campi e dei tipi
 | 
			
		||||
        memset(names, 0, numcols*2*sizeof(char*));
 | 
			
		||||
        const short nMaxCols = 256;
 | 
			
		||||
        char* values[nMaxCols];  // Lista dei valori del record corrente 
 | 
			
		||||
        memset(values, 0, sizeof(values));
 | 
			
		||||
    
 | 
			
		||||
        char* names[2*nMaxCols]; // Lista dei nomi dei campi e dei tipi
 | 
			
		||||
        memset(names, 0, sizeof(names));
 | 
			
		||||
 | 
			
		||||
        if (numcols > nMaxCols)
 | 
			
		||||
          numcols = nMaxCols;
 | 
			
		||||
 | 
			
		||||
        short 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))
 | 
			
		||||
          {
 | 
			
		||||
          case WXSQLITE_INTEGER: 
 | 
			
		||||
@ -114,15 +174,16 @@ ULONG XVT_SQLDB_SQLite3::Execute(const char* sql, ODBC_CALLBACK cb, void* jolly)
 | 
			
		||||
 | 
			
		||||
        while (rs.NextRow())
 | 
			
		||||
        {
 | 
			
		||||
          aValues.Empty();
 | 
			
		||||
          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)
 | 
			
		||||
            break;
 | 
			
		||||
          nRows++;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        delete values;   // butta la lista dei valori
 | 
			
		||||
        delete names;    // butta la lista dei nomi
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    catch(wxSQLite3Exception& e)
 | 
			
		||||
@ -212,6 +273,42 @@ BOOLEAN xvt_sql_close(XVT_SQLDB handle)
 | 
			
		||||
  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 n = 0;
 | 
			
		||||
 | 
			
		||||
@ -111,10 +111,11 @@ XVT_POPUP_OVER_ITEM
 | 
			
		||||
} XVT_POPUP_ALIGNMENT;
 | 
			
		||||
 | 
			
		||||
#define SZ_FNAME _MAX_FNAME
 | 
			
		||||
#define SZ_EXT   6
 | 
			
		||||
 | 
			
		||||
typedef struct {	/* file specification */
 | 
			
		||||
DIRECTORY dir;	/* directory */
 | 
			
		||||
char type[6];	/* file type/extension */
 | 
			
		||||
char type[SZ_EXT];	/* file type/extension */
 | 
			
		||||
char name[SZ_FNAME];	/* filename */
 | 
			
		||||
char creator[6];	/* file creator */
 | 
			
		||||
} FILE_SPEC;
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user