#endif
-/********** wxDbTable::wxDbTable() **********/
+/********** wxDbColDef::wxDbColDef() Constructor **********/
+wxDbColDef::wxDbColDef()
+{
+ Initialize();
+} // Constructor
+
+
+bool wxDbColDef::Initialize()
+{
+ ColName[0] = 0;
+ DbDataType = DB_DATA_TYPE_INTEGER;
+ SqlCtype = SQL_C_LONG;
+ PtrDataObj = NULL;
+ SzDataObj = 0;
+ KeyField = FALSE;
+ Updateable = FALSE;
+ InsertAllowed = FALSE;
+ DerivedCol = FALSE;
+ CbValue = 0;
+ Null = FALSE;
+
+ return TRUE;
+} // wxDbColDef::Initialize()
+
+
+/********** wxDbTable::wxDbTable() Constructor **********/
wxDbTable::wxDbTable(wxDb *pwxDb, const wxString &tblName, const int nCols,
const wxString &qryTblName, bool qryOnly, const wxString &tblPath)
{
wxString s;
tableID = ++lastTableID;
- s.Printf(wxT("wxDbTable constructor (%-20s) tableID:[%6lu] pDb:[%p]"), tblName,tableID,pDb);
+ s.Printf(wxT("wxDbTable constructor (%-20s) tableID:[%6lu] pDb:[%p]"), tblName.c_str(), tableID, pDb);
#ifdef __WXDEBUG__
wxTablesInUse *tableInUse;
wxString s;
if (pDb)
{
- s.Printf(wxT("wxDbTable destructor (%-20s) tableID:[%6lu] pDb:[%p]"), tableName,tableID,pDb);
+ s.Printf(wxT("wxDbTable destructor (%-20s) tableID:[%6lu] pDb:[%p]"), tableName.c_str(), tableID, pDb);
pDb->WriteSqlLog(s);
}
if (!queryOnly)
{
if (hstmtInsert)
+ {
+/*
+ODBC 3.0 says to use this form
+ if (SQLFreeHandle(*hstmtDel, SQL_DROP) != SQL_SUCCESS)
+*/
if (SQLFreeStmt(hstmtInsert, SQL_DROP) != SQL_SUCCESS)
pDb->DispAllErrors(henv, hdbc);
+ }
if (hstmtDelete)
+ {
+/*
+ODBC 3.0 says to use this form
+ if (SQLFreeHandle(*hstmtDel, SQL_DROP) != SQL_SUCCESS)
+*/
if (SQLFreeStmt(hstmtDelete, SQL_DROP) != SQL_SUCCESS)
+ pDb->DispAllErrors(henv, hdbc);
+ }
if (hstmtUpdate)
+ {
+/*
+ODBC 3.0 says to use this form
+ if (SQLFreeHandle(*hstmtDel, SQL_DROP) != SQL_SUCCESS)
+*/
if (SQLFreeStmt(hstmtUpdate, SQL_DROP) != SQL_SUCCESS)
pDb->DispAllErrors(henv, hdbc);
+ }
}
if (hstmtInternal)
+ {
if (SQLFreeStmt(hstmtInternal, SQL_DROP) != SQL_SUCCESS)
pDb->DispAllErrors(henv, hdbc);
+ }
// Delete dynamically allocated cursors
if (hstmtDefault)
else
colDefs[i].CbValue = 0;
break;
+ case DB_DATA_TYPE_BLOB:
+ fSqlType = pDb->GetTypeInfBlob().FsqlType;
+ precision = 50000;
+ scale = 0;
+ if (colDefs[i].Null)
+ colDefs[i].CbValue = SQL_NULL_DATA;
+ else
+ colDefs[i].CbValue = SQL_LEN_DATA_AT_EXEC(colDefs[i].SzDataObj);
+ break;
}
if (forUpdate)
{
wxString p;
if (!tablePath.IsEmpty())
- p.Printf(wxT("Error opening '%s/%s'.\n"),tablePath,tableName);
+ p.Printf(wxT("Error opening '%s/%s'.\n"),tablePath.c_str(),tableName.c_str());
else
- p.Printf(wxT("Error opening '%s'.\n"), tableName);
+ p.Printf(wxT("Error opening '%s'.\n"), tableName.c_str());
p += s;
pDb->LogError(p.GetData());
if (!queryOnly && noCols > 0)
{
bool needComma = FALSE;
- sqlStmt.Printf(wxT("INSERT INTO %s ("), tableName);
+ sqlStmt.Printf(wxT("INSERT INTO %s ("), tableName.c_str());
for (i = 0; i < noCols; i++)
{
if (! colDefs[i].InsertAllowed)
// delete all records from the database in this case.
if (typeOfDel == DB_DEL_WHERE && (pWhereClause.Length() == 0))
{
- pSqlStmt.Printf(wxT("DELETE FROM %s"), tableName);
+ pSqlStmt.Printf(wxT("DELETE FROM %s"), tableName.c_str());
return;
}
- pSqlStmt.Printf(wxT("DELETE FROM %s WHERE "), tableName);
+ pSqlStmt.Printf(wxT("DELETE FROM %s WHERE "), tableName.c_str());
// Append the WHERE clause to the SQL DELETE statement
switch(typeOfDel)
bool firstColumn = TRUE;
- pSqlStmt.Printf(wxT("UPDATE %s SET "), tableName);
+ pSqlStmt.Printf(wxT("UPDATE %s SET "), tableName.c_str());
// Append a list of columns to be updated
int i;
case DB_DATA_TYPE_DATE:
cout << pDb->typeInfDate.TypeName;
break;
+ case DB_DATA_TYPE_BLOB:
+ cout << pDb->typeInfBlob.TypeName;
+ break;
}
cout << endl;
}
// Build a CREATE TABLE string from the colDefs structure.
bool needComma = FALSE;
- sqlStmt.Printf(wxT("CREATE TABLE %s ("), tableName);
+ sqlStmt.Printf(wxT("CREATE TABLE %s ("), tableName.c_str());
for (i = 0; i < noCols; i++)
{
case DB_DATA_TYPE_DATE:
sqlStmt += pDb->GetTypeInfDate().TypeName;
break;
+ case DB_DATA_TYPE_BLOB:
+ sqlStmt += pDb->GetTypeInfBlob().TypeName;
+ break;
}
// For varchars, append the size of the string
- if (colDefs[i].DbDataType == DB_DATA_TYPE_VARCHAR)
+ if (colDefs[i].DbDataType == DB_DATA_TYPE_VARCHAR)// ||
+// colDefs[i].DbDataType == DB_DATA_TYPE_BLOB)
{
wxString s;
s.Printf(wxT("(%d)"), colDefs[i].SzDataObj);
wxString sqlStmt;
- sqlStmt.Printf(wxT("DROP TABLE %s"), tableName);
+ sqlStmt.Printf(wxT("DROP TABLE %s"), tableName.c_str());
pDb->WriteSqlLog(sqlStmt);
wxString sqlStmt;
if (pDb->Dbms() == dbmsACCESS || pDb->Dbms() == dbmsMY_SQL)
- sqlStmt.Printf(wxT("DROP INDEX %s ON %s"),idxName,tableName);
+ sqlStmt.Printf(wxT("DROP INDEX %s ON %s"),idxName.c_str(), tableName.c_str());
else if ((pDb->Dbms() == dbmsMS_SQL_SERVER) ||
(pDb->Dbms() == dbmsSYBASE_ASE))
- sqlStmt.Printf(wxT("DROP INDEX %s.%s"),tableName,idxName);
+ sqlStmt.Printf(wxT("DROP INDEX %s.%s"),tableName.c_str(), idxName.c_str());
else
- sqlStmt.Printf(wxT("DROP INDEX %s"),idxName);
+ sqlStmt.Printf(wxT("DROP INDEX %s"),idxName.c_str());
pDb->WriteSqlLog(sqlStmt);
pColDataPtrs[index].SzDataObj = sizeof(TIMESTAMP_STRUCT);
pColDataPtrs[index].SqlCtype = SQL_C_TIMESTAMP;
break;
+ case DB_DATA_TYPE_BLOB:
+ int notSupportedYet = 0;
+ wxASSERT_MSG(notSupportedYet, wxT("This form of ::SetColDefs() cannot be used with BLOB columns"));
+ pColDataPtrs[index].PtrDataObj = /*BLOB ADDITION NEEDED*/NULL;
+ pColDataPtrs[index].SzDataObj = /*BLOB ADDITION NEEDED*/sizeof(void *);
+ pColDataPtrs[index].SqlCtype = SQL_VARBINARY;
+ break;
+ }
+ if (pColDataPtrs[index].PtrDataObj != NULL)
+ SetColDefs (index,pColInfs[index].colName,pColInfs[index].dbDataType, pColDataPtrs[index].PtrDataObj, pColDataPtrs[index].SqlCtype, pColDataPtrs[index].SzDataObj);
+ else
+ {
+ // Unable to build all the column definitions, as either one of
+ // the calls to "new" failed above, or there was a BLOB field
+ // to have a column definition for. If BLOBs are to be used,
+ // the other form of ::SetColDefs() must be used, as it is impossible
+ // to know the maximum size to create the PtrDataObj to be.
+ delete [] pColDataPtrs;
+ return NULL;
}
- SetColDefs (index,pColInfs[index].colName,pColInfs[index].dbDataType, pColDataPtrs[index].PtrDataObj, pColDataPtrs[index].SqlCtype, pColDataPtrs[index].SzDataObj);
}
}
if (!hstmtDel) // Cursor already deleted
return(result);
+/*
+ODBC 3.0 says to use this form
+ if (SQLFreeHandle(*hstmtDel, SQL_DROP) != SQL_SUCCESS)
+
+*/
if (SQLFreeStmt(*hstmtDel, SQL_DROP) != SQL_SUCCESS)
{
pDb->DispAllErrors(henv, hdbc);