int i;
wxString sqlStmt;
wxString s;
-// int NumKeyCols=0;
// Calculate the maximum size of the concatenated
// keys for use with wxDbGrid
{
if (colDefs[i].KeyField)
{
-// NumKeyCols++;
m_keysize += colDefs[i].SzDataObj;
}
}
s.Empty();
+
+ bool exists = true;
+ if (checkTableExists)
+ {
+ if (pDb->Dbms() == dbmsPOSTGRES)
+ exists = pDb->TableExists(tableName, NULL, tablePath);
+ else
+ exists = pDb->TableExists(tableName, pDb->GetUsername(), tablePath);
+ }
+
// Verify that the table exists in the database
- if (checkTableExists && !pDb->TableExists(tableName, pDb->GetUsername(), tablePath))
+ if (!exists)
{
s = wxT("Table/view does not exist in the database");
if ( *(pDb->dbInf.accessibleTables) == wxT('Y'))
else if (checkPrivileges)
{
// Verify the user has rights to access the table.
- // Shortcut boolean evaluation to optimize out call to
- // TablePrivileges
- //
- // Unfortunately this optimization doesn't seem to be
- // reliable!
- if (// *(pDb->dbInf.accessibleTables) == 'N' &&
- !pDb->TablePrivileges(tableName, wxT("SELECT"), pDb->GetUsername(), pDb->GetUsername(), tablePath))
+ bool hasPrivs wxDUMMY_INITIALIZE(true);
+
+ if (pDb->Dbms() == dbmsPOSTGRES)
+ hasPrivs = pDb->TablePrivileges(tableName, wxT("SELECT"), pDb->GetUsername(), NULL, tablePath);
+ else
+ hasPrivs = pDb->TablePrivileges(tableName, wxT("SELECT"), pDb->GetUsername(), pDb->GetUsername(), tablePath);
+
+ if (!hasPrivs)
s = wxT("Connecting user does not have sufficient privileges to access this table.\n");
}
- if (!s.IsEmpty())
+ if (!s.empty())
{
wxString p;
- if (!tablePath.IsEmpty())
+ if (!tablePath.empty())
p.Printf(wxT("Error opening '%s/%s'.\n"),tablePath.c_str(),tableName.c_str());
else
p.Printf(wxT("Error opening '%s'.\n"), tableName.c_str());
if (needComma)
sqlStmt += wxT(",");
sqlStmt += pDb->SQLColumnName(colDefs[i].ColName);
-// sqlStmt += colDefs[i].ColName;
needComma = true;
}
needComma = false;
{
pSqlStmt += wxT(",");
pSqlStmt += pDb->SQLTableName(queryTableName);
-// pSqlStmt += queryTableName;
pSqlStmt += wxT(".ROWID");
}
else
switch(colDefs[colNumber].SqlCtype)
{
case SQL_C_CHAR:
-#ifndef __UNIX__
+#ifdef SQL_C_WCHAR
case SQL_C_WCHAR:
-#endif
+#endif
//case SQL_C_WXCHAR: SQL_C_WXCHAR is covered by either SQL_C_CHAR or SQL_C_WCHAR
colValue.Printf(wxT("'%s'"), (UCHAR FAR *) colDefs[colNumber].PtrDataObj);
break;
(pDb->Dbms() == dbmsSYBASE_ASE && !wxStrcmp(pDb->sqlState,wxT("37000"))) ||
(pDb->Dbms() == dbmsMS_SQL_SERVER && !wxStrcmp(pDb->sqlState,wxT("S1000"))) ||
(pDb->Dbms() == dbmsINTERBASE && !wxStrcmp(pDb->sqlState,wxT("S1000"))) ||
+ (pDb->Dbms() == dbmsMAXDB && !wxStrcmp(pDb->sqlState,wxT("S1000"))) ||
(pDb->Dbms() == dbmsFIREBIRD && !wxStrcmp(pDb->sqlState,wxT("HY000"))) ||
(pDb->Dbms() == dbmsSYBASE_ASE && !wxStrcmp(pDb->sqlState,wxT("S0002"))) || // Base table not found
(pDb->Dbms() == dbmsMY_SQL && !wxStrcmp(pDb->sqlState,wxT("42S12"))) || // tested by Christopher Ludwik Marino-Cebulski using v3.23.21beta
switch(colDefs[colNumber].SqlCtype)
{
case SQL_C_CHAR:
-#ifndef __UNIX__
+#ifdef SQL_C_WCHAR
case SQL_C_WCHAR:
#endif
//case SQL_C_WXCHAR: SQL_C_WXCHAR is covered by either SQL_C_CHAR or SQL_C_WCHAR
{
switch (colDefs[colNumber].SqlCtype)
{
+#if wxUSE_UNICODE
+ #if defined(SQL_WCHAR)
+ case SQL_WCHAR:
+ #endif
+ #if defined(SQL_WVARCHAR)
+ case SQL_WVARCHAR:
+ #endif
+#endif
case SQL_CHAR:
case SQL_VARCHAR:
val = (wxChar *)(colDefs[colNumber].PtrDataObj);
switch (colDefs[colNumber].SqlCtype)
{
+#if wxUSE_UNICODE
+ #if defined(SQL_WCHAR)
+ case SQL_WCHAR:
+ #endif
+ #if defined(SQL_WVARCHAR)
+ case SQL_WVARCHAR:
+ #endif
+#endif
case SQL_CHAR:
case SQL_VARCHAR:
csstrncpyt((wxChar *)(colDefs[colNumber].PtrDataObj),