Added a check for a '.' in the column name before prepending a table name to the column name to avoid incorrect TABLE.COLUMN names when using a FROM clause
SF PATCH#766404 - SetColNull() was not correctly setting CbValue = SQL_NULL_DATA so that NULL columns still appeared to have data in some cases Cleaned up some internal variable naming conventions git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@22589 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -24,6 +24,7 @@
|
|||||||
// SYNOPSIS START
|
// SYNOPSIS START
|
||||||
// SYNOPSIS STOP
|
// SYNOPSIS STOP
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef __GNUG__
|
#ifdef __GNUG__
|
||||||
#pragma implementation "dbtable.h"
|
#pragma implementation "dbtable.h"
|
||||||
#endif
|
#endif
|
||||||
@@ -57,7 +58,6 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
//#include <assert.h>
|
|
||||||
|
|
||||||
#include "wx/dbtable.h"
|
#include "wx/dbtable.h"
|
||||||
|
|
||||||
@@ -80,6 +80,16 @@ ULONG lastTableID = 0;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
void csstrncpyt(char *target, const char *source, int n)
|
||||||
|
{
|
||||||
|
while ( (*target++ = *source++) != '\0' && --n )
|
||||||
|
;
|
||||||
|
|
||||||
|
*target = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/********** wxDbColDef::wxDbColDef() Constructor **********/
|
/********** wxDbColDef::wxDbColDef() Constructor **********/
|
||||||
wxDbColDef::wxDbColDef()
|
wxDbColDef::wxDbColDef()
|
||||||
{
|
{
|
||||||
@@ -1031,17 +1041,17 @@ void wxDbTable::BuildSelectStmt(wxString &pSqlStmt, int typeOfSelect, bool disti
|
|||||||
|
|
||||||
// Add the column list
|
// Add the column list
|
||||||
int i;
|
int i;
|
||||||
|
wxString tStr;
|
||||||
for (i = 0; i < noCols; i++)
|
for (i = 0; i < noCols; i++)
|
||||||
{
|
{
|
||||||
|
tStr = colDefs[i].ColName;
|
||||||
// If joining tables, the base table column names must be qualified to avoid ambiguity
|
// If joining tables, the base table column names must be qualified to avoid ambiguity
|
||||||
if (appendFromClause || pDb->Dbms() == dbmsACCESS)
|
if ((appendFromClause || pDb->Dbms() == dbmsACCESS) && !tStr.Find(wxT('.')))
|
||||||
{
|
{
|
||||||
pSqlStmt += pDb->SQLTableName(queryTableName.c_str());
|
pSqlStmt += pDb->SQLTableName(queryTableName.c_str());
|
||||||
// pSqlStmt += queryTableName;
|
|
||||||
pSqlStmt += wxT(".");
|
pSqlStmt += wxT(".");
|
||||||
}
|
}
|
||||||
pSqlStmt += pDb->SQLColumnName(colDefs[i].ColName);
|
pSqlStmt += pDb->SQLColumnName(colDefs[i].ColName);
|
||||||
// pSqlStmt += colDefs[i].ColName;
|
|
||||||
if (i + 1 < noCols)
|
if (i + 1 < noCols)
|
||||||
pSqlStmt += wxT(",");
|
pSqlStmt += wxT(",");
|
||||||
}
|
}
|
||||||
@@ -1230,56 +1240,59 @@ void wxDbTable::BuildWhereClause(wxString &pWhereClause, int typeOfWhere,
|
|||||||
wxString colValue;
|
wxString colValue;
|
||||||
|
|
||||||
// Loop through the columns building a where clause as you go
|
// Loop through the columns building a where clause as you go
|
||||||
int i;
|
int colNo;
|
||||||
for (i = 0; i < noCols; i++)
|
for (colNo = 0; colNo < noCols; colNo++)
|
||||||
{
|
{
|
||||||
// Determine if this column should be included in the WHERE clause
|
// Determine if this column should be included in the WHERE clause
|
||||||
if ((typeOfWhere == DB_WHERE_KEYFIELDS && colDefs[i].KeyField) ||
|
if ((typeOfWhere == DB_WHERE_KEYFIELDS && colDefs[colNo].KeyField) ||
|
||||||
(typeOfWhere == DB_WHERE_MATCHING && (!IsColNull(i))))
|
(typeOfWhere == DB_WHERE_MATCHING && (!IsColNull(colNo))))
|
||||||
{
|
{
|
||||||
// Skip over timestamp columns
|
// Skip over timestamp columns
|
||||||
if (colDefs[i].SqlCtype == SQL_C_TIMESTAMP)
|
if (colDefs[colNo].SqlCtype == SQL_C_TIMESTAMP)
|
||||||
continue;
|
continue;
|
||||||
// If there is more than 1 column, join them with the keyword "AND"
|
// If there is more than 1 column, join them with the keyword "AND"
|
||||||
if (moreThanOneColumn)
|
if (moreThanOneColumn)
|
||||||
pWhereClause += wxT(" AND ");
|
pWhereClause += wxT(" AND ");
|
||||||
else
|
else
|
||||||
moreThanOneColumn = TRUE;
|
moreThanOneColumn = TRUE;
|
||||||
|
|
||||||
// Concatenate where phrase for the column
|
// Concatenate where phrase for the column
|
||||||
if (qualTableName.Length())
|
wxString tStr = colDefs[colNo].ColName;
|
||||||
|
|
||||||
|
if (qualTableName.Length() && !tStr.Find(wxT('.')))
|
||||||
{
|
{
|
||||||
pWhereClause += pDb->SQLTableName(qualTableName);
|
pWhereClause += pDb->SQLTableName(qualTableName);
|
||||||
// pWhereClause += qualTableName;
|
|
||||||
pWhereClause += wxT(".");
|
pWhereClause += wxT(".");
|
||||||
}
|
}
|
||||||
pWhereClause += pDb->SQLColumnName(colDefs[i].ColName);
|
pWhereClause += pDb->SQLColumnName(colDefs[colNo].ColName);
|
||||||
// pWhereClause += colDefs[i].ColName;
|
|
||||||
if (useLikeComparison && (colDefs[i].SqlCtype == SQL_C_CHAR))
|
if (useLikeComparison && (colDefs[colNo].SqlCtype == SQL_C_CHAR))
|
||||||
pWhereClause += wxT(" LIKE ");
|
pWhereClause += wxT(" LIKE ");
|
||||||
else
|
else
|
||||||
pWhereClause += wxT(" = ");
|
pWhereClause += wxT(" = ");
|
||||||
switch(colDefs[i].SqlCtype)
|
|
||||||
|
switch(colDefs[colNo].SqlCtype)
|
||||||
{
|
{
|
||||||
case SQL_C_CHAR:
|
case SQL_C_CHAR:
|
||||||
colValue.Printf(wxT("'%s'"), (UCHAR FAR *) colDefs[i].PtrDataObj);
|
colValue.Printf(wxT("'%s'"), (UCHAR FAR *) colDefs[colNo].PtrDataObj);
|
||||||
break;
|
break;
|
||||||
case SQL_C_SSHORT:
|
case SQL_C_SSHORT:
|
||||||
colValue.Printf(wxT("%hi"), *((SWORD *) colDefs[i].PtrDataObj));
|
colValue.Printf(wxT("%hi"), *((SWORD *) colDefs[colNo].PtrDataObj));
|
||||||
break;
|
break;
|
||||||
case SQL_C_USHORT:
|
case SQL_C_USHORT:
|
||||||
colValue.Printf(wxT("%hu"), *((UWORD *) colDefs[i].PtrDataObj));
|
colValue.Printf(wxT("%hu"), *((UWORD *) colDefs[colNo].PtrDataObj));
|
||||||
break;
|
break;
|
||||||
case SQL_C_SLONG:
|
case SQL_C_SLONG:
|
||||||
colValue.Printf(wxT("%li"), *((SDWORD *) colDefs[i].PtrDataObj));
|
colValue.Printf(wxT("%li"), *((SDWORD *) colDefs[colNo].PtrDataObj));
|
||||||
break;
|
break;
|
||||||
case SQL_C_ULONG:
|
case SQL_C_ULONG:
|
||||||
colValue.Printf(wxT("%lu"), *((UDWORD *) colDefs[i].PtrDataObj));
|
colValue.Printf(wxT("%lu"), *((UDWORD *) colDefs[colNo].PtrDataObj));
|
||||||
break;
|
break;
|
||||||
case SQL_C_FLOAT:
|
case SQL_C_FLOAT:
|
||||||
colValue.Printf(wxT("%.6f"), *((SFLOAT *) colDefs[i].PtrDataObj));
|
colValue.Printf(wxT("%.6f"), *((SFLOAT *) colDefs[colNo].PtrDataObj));
|
||||||
break;
|
break;
|
||||||
case SQL_C_DOUBLE:
|
case SQL_C_DOUBLE:
|
||||||
colValue.Printf(wxT("%.6f"), *((SDOUBLE *) colDefs[i].PtrDataObj));
|
colValue.Printf(wxT("%.6f"), *((SDOUBLE *) colDefs[colNo].PtrDataObj));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
pWhereClause += colValue;
|
pWhereClause += colValue;
|
||||||
@@ -2481,7 +2494,10 @@ bool wxDbTable::SetColNull(UWORD colNo, bool set)
|
|||||||
{
|
{
|
||||||
colDefs[colNo].Null = set;
|
colDefs[colNo].Null = set;
|
||||||
if (set) // Blank out the values in the member variable
|
if (set) // Blank out the values in the member variable
|
||||||
ClearMemberVar(colNo,FALSE); // Must call with FALSE, or infinite recursion will happen
|
{
|
||||||
|
colDefs[colNo].CbValue = SQL_NULL_DATA; // SF PATCH#766404
|
||||||
|
ClearMemberVar(colNo,FALSE); // Must call with FALSE, or infinite recursion will happen
|
||||||
|
}
|
||||||
return(TRUE);
|
return(TRUE);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -2493,18 +2509,21 @@ bool wxDbTable::SetColNull(UWORD colNo, bool set)
|
|||||||
/********** wxDbTable::SetColNull() **********/
|
/********** wxDbTable::SetColNull() **********/
|
||||||
bool wxDbTable::SetColNull(const wxString &colName, bool set)
|
bool wxDbTable::SetColNull(const wxString &colName, bool set)
|
||||||
{
|
{
|
||||||
int i;
|
int colNo;
|
||||||
for (i = 0; i < noCols; i++)
|
for (colNo = 0; colNo < noCols; colNo++)
|
||||||
{
|
{
|
||||||
if (!wxStricmp(colName, colDefs[i].ColName))
|
if (!wxStricmp(colName, colDefs[colNo].ColName))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i < noCols)
|
if (colNo < noCols)
|
||||||
{
|
{
|
||||||
colDefs[i].Null = set;
|
colDefs[colNo].Null = set;
|
||||||
if (set) // Blank out the values in the member variable
|
if (set) // Blank out the values in the member variable
|
||||||
ClearMemberVar(i,FALSE); // Must call with FALSE, or infinite recursion will happen
|
{
|
||||||
|
colDefs[colNo].CbValue = SQL_NULL_DATA; // SF PATCH#766404
|
||||||
|
ClearMemberVar(colNo,FALSE); // Must call with FALSE, or infinite recursion will happen
|
||||||
|
}
|
||||||
return(TRUE);
|
return(TRUE);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -2600,7 +2619,7 @@ void wxDbTable::SetRowMode(const rowmode_t rowmode)
|
|||||||
SetCursor(hstmtDefault);
|
SetCursor(hstmtDefault);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
assert(0);
|
wxASSERT(0);
|
||||||
}
|
}
|
||||||
} // wxDbTable::SetRowMode()
|
} // wxDbTable::SetRowMode()
|
||||||
|
|
||||||
@@ -2656,14 +2675,6 @@ wxVariant wxDbTable::GetCol(const int colNo) const
|
|||||||
} // wxDbTable::GetCol()
|
} // wxDbTable::GetCol()
|
||||||
|
|
||||||
|
|
||||||
void csstrncpyt(char *s, const char *t, int n)
|
|
||||||
{
|
|
||||||
while ( (*s++ = *t++) != '\0' && --n )
|
|
||||||
;
|
|
||||||
|
|
||||||
*s = '\0';
|
|
||||||
}
|
|
||||||
|
|
||||||
void wxDbTable::SetCol(const int colNo, const wxVariant val)
|
void wxDbTable::SetCol(const int colNo, const wxVariant val)
|
||||||
{
|
{
|
||||||
//FIXME: Add proper wxDateTime support to wxVariant..
|
//FIXME: Add proper wxDateTime support to wxVariant..
|
||||||
|
Reference in New Issue
Block a user