]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/dbtable.cpp
More _T() in asserts...
[wxWidgets.git] / src / common / dbtable.cpp
index decce99426d45cdd62c74a4b118fee2dab83238b..d1166229c46901a0d7ec913a9e06cc7960a135ed 100644 (file)
@@ -132,7 +132,7 @@ wxTable::wxTable(wxDB *pwxDB, const char *tblName, const int nCols, const char *
                        // Datasource does not support static cursors.  Driver
                        // will substitute a cursor type.  Call SQLGetStmtOption()
                        // to determine which cursor type was selected.
-                       if (SQLGetStmtOption(c1, SQL_CURSOR_TYPE, &cursorType) != SQL_SUCCESS)
+                       if (SQLGetStmtOption(c1, SQL_CURSOR_TYPE, (UCHAR*) &cursorType) != SQL_SUCCESS)
                                pDb->DispAllErrors(henv, hdbc, c1);
 #ifdef _CONSOLE
                        cout << "Static cursor changed to: ";
@@ -353,7 +353,7 @@ bool wxTable::query(int queryType, bool forUpdate, bool distinct, char *pSqlStmt
        // Make sure the cursor is closed first
        if (! CloseCursor(hstmt))
                return(FALSE);
-
+               
        // Execute the SQL SELECT statement
        if (SQLExecDirect(hstmt, (UCHAR FAR *) (queryType == DB_SELECT_STATEMENT ? pSqlStmt : sqlStmt),
                               SQL_NTS) != SQL_SUCCESS)
@@ -494,7 +494,7 @@ UWORD wxTable::GetRowNum(void)
 {
        UDWORD rowNum;
 
-       if (SQLGetStmtOption(hstmt, SQL_ROW_NUMBER, &rowNum) != SQL_SUCCESS)
+       if (SQLGetStmtOption(hstmt, SQL_ROW_NUMBER, (UCHAR*) &rowNum) != SQL_SUCCESS)
        {
                pDb->DispAllErrors(henv, hdbc, hstmt);
                return(0);
@@ -508,9 +508,9 @@ UWORD wxTable::GetRowNum(void)
 /********** wxTable::bindInsertParams() **********/
 bool wxTable::bindInsertParams(void)
 {
-       SWORD   fSqlType;
-       UDWORD  precision;
-       SWORD   scale;
+       SWORD   fSqlType = 0;
+       UDWORD  precision = 0;
+       SWORD   scale = 0;
 
        // Bind each column (that can be inserted) of the table to a parameter marker
        for (int i = 0; i < noCols; i++)
@@ -550,7 +550,7 @@ bool wxTable::bindInsertParams(void)
                        break;
                }
                if (SQLBindParameter(hstmtInsert, i+1, SQL_PARAM_INPUT, colDefs[i].SqlCtype,
-                                                                       fSqlType, precision, scale, colDefs[i].PtrDataObj, 
+                                                                       fSqlType, precision, scale, (UCHAR*) colDefs[i].PtrDataObj, 
                                                                        precision+1,&colDefs[i].CbValue) != SQL_SUCCESS)
                        return(pDb->DispAllErrors(henv, hdbc, hstmtInsert));
        }
@@ -563,9 +563,9 @@ bool wxTable::bindInsertParams(void)
 /********** wxTable::bindUpdateParams() **********/
 bool wxTable::bindUpdateParams(void)
 {
-       SWORD   fSqlType;
-       UDWORD  precision;
-       SWORD   scale;
+       SWORD   fSqlType = 0;
+       UDWORD  precision = 0;
+       SWORD   scale = 0;
        
        // Bind each UPDATEABLE column of the table to a parameter marker
        for (int i = 0, colNo = 1; i < noCols; i++)
@@ -605,7 +605,7 @@ bool wxTable::bindUpdateParams(void)
                        break;
                }
                if (SQLBindParameter(hstmtUpdate, colNo++, SQL_PARAM_INPUT, colDefs[i].SqlCtype,
-                                                                       fSqlType, precision, scale, colDefs[i].PtrDataObj, 
+                                                                       fSqlType, precision, scale, (UCHAR*) colDefs[i].PtrDataObj, 
                                                                        precision+1, &colDefs[i].CbValue) != SQL_SUCCESS)
                        return(pDb->DispAllErrors(henv, hdbc, hstmtUpdate));
        }
@@ -623,7 +623,7 @@ bool wxTable::bindCols(HSTMT cursor)
        // Bind each column of the table to a memory address for fetching data
        for (int i = 0; i < noCols; i++)
        {
-               if (SQLBindCol(cursor, i+1, colDefs[i].SqlCtype, colDefs[i].PtrDataObj,
+               if (SQLBindCol(cursor, i+1, colDefs[i].SqlCtype, (UCHAR*) colDefs[i].PtrDataObj,
                                                        colDefs[i].SzDataObj, &cb) != SQL_SUCCESS)
                        return(pDb->DispAllErrors(henv, hdbc, cursor));
        }
@@ -661,12 +661,24 @@ bool wxTable::CreateTable(void)
        sprintf(sqlStmt, "DROP TABLE %s", tableName);
        if (SQLExecDirect(hstmt, (UCHAR FAR *) sqlStmt, SQL_NTS) != SQL_SUCCESS)
        {
-               // Check for sqlState = S0002, "Table or view not found".
-               // Ignore this error, bomb out on any other error.
-               // SQL Sybase Anwhere v5.5 returns an access violation error here
-               // (sqlstate = 42000) rather than an S0002.
+               /* Check for sqlState = S0002, "Table or view not found".
+                * Ignore this error, bomb out on any other error.
+                * SQL Sybase Anwhere v5.5 returns an access violation error here
+                * (sqlstate = 42000) rather than an S0002. */
+                
+               /* PostgreSQL 6.4.0 returns "08S01" or in written form
+                  "ERROR: Relation ... Does Not Exist", Robert Roebling */
+               
+               /* MySQL 3.23.33b returns "S1000" or in written form
+                  "ERROR: Unknown table ...", Robert Roebling */
+                  
+               /* This routine is bullshit, Robert Roebling */
+               
                pDb->GetNextError(henv, hdbc, hstmt);
-               if (strcmp(pDb->sqlState, "S0002") && strcmp(pDb->sqlState, "42000"))
+               if (strcmp(pDb->sqlState, "S0002") && 
+                   strcmp(pDb->sqlState, "S1000") &&
+                   strcmp(pDb->sqlState, "42000") &&
+                   strcmp(pDb->sqlState, "08S01"))
                {
                        pDb->DispNextError();
                        pDb->DispAllErrors(henv, hdbc, hstmt);
@@ -747,6 +759,14 @@ bool wxTable::CreateTable(void)
                        sprintf(s, "(%d)", colDefs[i].SzDataObj);
                        strcat(sqlStmt, s);
                }
+               
+#ifdef __WXGTK__
+               if (colDefs[i].KeyField)
+               {
+                       strcat(sqlStmt, " NOT NULL");
+               }
+#endif
+               
                needComma = TRUE;
        }
        // If there is a primary key defined, include it in the create statement
@@ -760,9 +780,15 @@ bool wxTable::CreateTable(void)
        }
        if (j)  // Found a keyfield
        {
+#ifndef __WXGTK__
+  /* MySQL goes out on this one. We also declare the relevant key NON NULL above */
                strcat(sqlStmt, ",CONSTRAINT ");
                strcat(sqlStmt, tableName);
                strcat(sqlStmt, "_PIDX PRIMARY KEY (");
+#else
+               strcat(sqlStmt, ", PRIMARY KEY (");
+#endif
+
                // List column name(s) of column(s) comprising the primary key
                for (i = j = 0; i < noCols; i++)
                {
@@ -776,8 +802,8 @@ bool wxTable::CreateTable(void)
           strcat(sqlStmt, ")");
        }
        // Append the closing parentheses for the create table statement
-   strcat(sqlStmt, ")");
-
+        strcat(sqlStmt, ")");
+   
        pDb->WriteSqlLog(sqlStmt);
 
 #ifdef _CONSOLE
@@ -824,12 +850,17 @@ bool wxTable::CreateIndex(char * idxName, bool unique, int noIdxCols, CidxDef *p
        for (int i = 0; i < noIdxCols; i++)
        {
                strcat(sqlStmt, pIdxDefs[i].ColName);
+
+      /* Postgres doesnt cope with ASC */
+#ifndef __WXGTK__
                if (pIdxDefs[i].Ascending)
                        strcat(sqlStmt, " ASC");
                else
                        strcat(sqlStmt, " DESC");
+#endif
+
                if ((i + 1) < noIdxCols)
-                       strcat(sqlStmt, ",");
+                       strcat(sqlStmt, ", ");
        }
        
        // Append closing parentheses
@@ -1040,7 +1071,7 @@ void wxTable::GetUpdateStmt(char *pSqlStmt, int typeOfUpd, char *pWhereClause)
                        // Get the ROWID value.  If not successful retreiving the ROWID,
                        // simply fall down through the code and build the WHERE clause
                        // based on the key fields.
-                       if (SQLGetData(hstmt, noCols+1, SQL_C_CHAR, rowid, ROWID_LEN, &cb) == SQL_SUCCESS)
+                       if (SQLGetData(hstmt, noCols+1, SQL_C_CHAR, (UCHAR*) rowid, ROWID_LEN, &cb) == SQL_SUCCESS)
                        {
                                strcat(pSqlStmt, "ROWID = '");
                                strcat(pSqlStmt, rowid);
@@ -1092,7 +1123,7 @@ void wxTable::GetDeleteStmt(char *pSqlStmt, int typeOfDel, char *pWhereClause)
                        // Get the ROWID value.  If not successful retreiving the ROWID,
                        // simply fall down through the code and build the WHERE clause
                        // based on the key fields.
-                       if (SQLGetData(hstmt, noCols+1, SQL_C_CHAR, rowid, ROWID_LEN, &cb) == SQL_SUCCESS)
+                       if (SQLGetData(hstmt, noCols+1, SQL_C_CHAR, (UCHAR*) rowid, ROWID_LEN, &cb) == SQL_SUCCESS)
                        {
                                strcat(pSqlStmt, "ROWID = '");
                                strcat(pSqlStmt, rowid);
@@ -1216,9 +1247,11 @@ bool wxTable::IsColNull(int colNo)
 
 bool wxTable::CanSelectForUpdate(void)
 {
+#ifndef __WXGTK__
        if (pDb->dbInf.posStmts & SQL_PS_SELECT_FOR_UPDATE)
                return(TRUE);
        else
+#endif
                return(FALSE);
 
 }  // wxTable::CanSelectForUpdate()
@@ -1327,7 +1360,8 @@ void wxTable::SetColDefs (int index, char *fieldName, int dataType, void *pData,
                                                                 int cType, int size, bool keyField, bool upd,
                                                                 bool insAllow, bool derivedCol)
 {
-       if (strlen(fieldName) > DB_MAX_COLUMN_NAME_LEN)  // glt 4/21/97
+    // Please, no uint, it doesn't exist for VC++
+       if (strlen(fieldName) > (unsigned int) DB_MAX_COLUMN_NAME_LEN)  // glt 4/21/97
        {
                strncpy (colDefs[index].ColName, fieldName, DB_MAX_COLUMN_NAME_LEN);
                colDefs[index].ColName[DB_MAX_COLUMN_NAME_LEN] = 0;  // glt 10/23/97
@@ -1439,7 +1473,7 @@ ULONG wxTable::Count(void)
        }
 
        // Obtain the result
-       if (SQLGetData(hstmtCount, 1, SQL_C_ULONG, &l, sizeof(l), &cb) != SQL_SUCCESS)
+       if (SQLGetData(hstmtCount, 1, SQL_C_ULONG, (UCHAR*) &l, sizeof(l), &cb) != SQL_SUCCESS)
        {
                pDb->DispAllErrors(henv, hdbc, hstmtCount);
                return(0);
@@ -1480,7 +1514,7 @@ bool wxTable::Refresh(void)
                // Get the ROWID value.  If not successful retreiving the ROWID,
                // simply fall down through the code and build the WHERE clause
                // based on the key fields.
-               if (SQLGetData(hstmt, noCols+1, SQL_C_CHAR, rowid, ROWID_LEN, &cb) == SQL_SUCCESS)
+               if (SQLGetData(hstmt, noCols+1, SQL_C_CHAR, (UCHAR*) rowid, ROWID_LEN, &cb) == SQL_SUCCESS)
                {
                        strcat(whereClause, queryTableName);
                        strcat(whereClause, ".ROWID = '");