From 7eeba5114ce9c7eccdeb8bd68ee608bb7ba462e3 Mon Sep 17 00:00:00 2001 From: Julian Smart Date: Wed, 18 Jan 2006 13:15:04 +0000 Subject: [PATCH] Applied patch [ 1304191 ] support for MEMO fields Francesco Montorsi git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@36964 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/latex/wx/db.tex | 2 ++ include/wx/db.h | 3 +++ src/common/db.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ src/common/dbtable.cpp | 18 ++++++++++++++++++ 4 files changed, 64 insertions(+) diff --git a/docs/latex/wx/db.tex b/docs/latex/wx/db.tex index 0eec6208cf..1056eeabbb 100644 --- a/docs/latex/wx/db.tex +++ b/docs/latex/wx/db.tex @@ -3572,6 +3572,8 @@ wxDbTable constructor was called.} DB_DATA_TYPE_INTEGER : non-floating point numbers DB_DATA_TYPE_FLOAT : floating point numbers DB_DATA_TYPE_DATE : dates + DB_DATA_TYPE_BLOB : binary large objects + DB_DATA_TYPE_MEMO : large strings \end{verbatim} \docparam{pData}{Pointer to the data object that will hold the column's diff --git a/include/wx/db.h b/include/wx/db.h index edc4b293ee..5d7d67c220 100644 --- a/include/wx/db.h +++ b/include/wx/db.h @@ -158,6 +158,7 @@ const int DB_DATA_TYPE_INTEGER = 2; const int DB_DATA_TYPE_FLOAT = 3; const int DB_DATA_TYPE_DATE = 4; const int DB_DATA_TYPE_BLOB = 5; +const int DB_DATA_TYPE_MEMO = 6; const int DB_SELECT_KEYFIELDS = 1; const int DB_SELECT_WHERE = 2; @@ -555,6 +556,7 @@ private: wxDbSqlTypeInfo typeInfFloat; wxDbSqlTypeInfo typeInfDate; wxDbSqlTypeInfo typeInfBlob; + wxDbSqlTypeInfo typeInfMemo; #endif public: @@ -694,6 +696,7 @@ public: wxDbSqlTypeInfo GetTypeInfFloat() {return typeInfFloat;} wxDbSqlTypeInfo GetTypeInfDate() {return typeInfDate;} wxDbSqlTypeInfo GetTypeInfBlob() {return typeInfBlob;} + wxDbSqlTypeInfo GetTypeInfMemo() {return typeInfMemo;} // tableName can refer to a table, view, alias or synonym bool TableExists(const wxString &tableName, const wxChar *userID=NULL, diff --git a/src/common/db.cpp b/src/common/db.cpp index d652a46bd6..486ce397dd 100644 --- a/src/common/db.cpp +++ b/src/common/db.cpp @@ -532,6 +532,12 @@ void wxDb::initialize() typeInfBlob.CaseSensitive = 0; typeInfBlob.MaximumScale = 0; + typeInfMemo.TypeName.Empty(); + typeInfMemo.FsqlType = 0; + typeInfMemo.Precision = 0; + typeInfMemo.CaseSensitive = 0; + typeInfMemo.MaximumScale = 0; + // Error reporting is turned OFF by default silent = true; @@ -650,6 +656,16 @@ bool wxDb::determineDataTypes(bool failOnDataTypeUnsupported) SQL_VARBINARY }; + // These are the possible SQL types we check for use agains the datasource we are connected + // to for the purpose of determining which data type to use for the MEMO column types + // (a type which allow to store large strings; like VARCHAR just with a bigger precision) + // + // NOTE: The first type in this enumeration that is determined to be supported by the + // datasource/driver is the one that will be used. + SWORD PossibleSqlMemoTypes[] = { + SQL_LONGVARCHAR, + }; + // Query the data source regarding data type information @@ -756,6 +772,16 @@ bool wxDb::determineDataTypes(bool failOnDataTypeUnsupported) else if (failOnDataTypeUnsupported) return false; + // --------------- MEMO --------------- + for (iIndex = 0; iIndex < WXSIZEOF(PossibleSqlMemoTypes) && + !getDataTypeInfo(PossibleSqlMemoTypes[iIndex], typeInfMemo); ++iIndex) + {} + + if (iIndex < WXSIZEOF(PossibleSqlMemoTypes)) + typeInfMemo.FsqlType = PossibleSqlMemoTypes[iIndex]; + else if (failOnDataTypeUnsupported) + return false; + return true; } // wxDb::determineDataTypes @@ -790,6 +816,7 @@ bool wxDb::open(bool failOnDataTypeUnsupported) cout << wxT("FLOAT DATA TYPE: ") << typeInfFloat.TypeName << endl; cout << wxT("DATE DATA TYPE: ") << typeInfDate.TypeName << endl; cout << wxT("BLOB DATA TYPE: ") << typeInfBlob.TypeName << endl; + cout << wxT("MEMO DATA TYPE: ") << typeInfMemo.TypeName << endl; cout << endl; #endif @@ -1050,12 +1077,20 @@ bool wxDb::Open(wxDb *copyDb) typeInfBlob.CaseSensitive = copyDb->typeInfBlob.CaseSensitive; typeInfBlob.MaximumScale = copyDb->typeInfBlob.MaximumScale; + // Memo + typeInfMemo.FsqlType = copyDb->typeInfMemo.FsqlType; + typeInfMemo.TypeName = copyDb->typeInfMemo.TypeName; + typeInfMemo.Precision = copyDb->typeInfMemo.Precision; + typeInfMemo.CaseSensitive = copyDb->typeInfMemo.CaseSensitive; + typeInfMemo.MaximumScale = copyDb->typeInfMemo.MaximumScale; + #ifdef DBDEBUG_CONSOLE cout << wxT("VARCHAR DATA TYPE: ") << typeInfVarchar.TypeName << endl; cout << wxT("INTEGER DATA TYPE: ") << typeInfInteger.TypeName << endl; cout << wxT("FLOAT DATA TYPE: ") << typeInfFloat.TypeName << endl; cout << wxT("DATE DATA TYPE: ") << typeInfDate.TypeName << endl; cout << wxT("BLOB DATA TYPE: ") << typeInfBlob.TypeName << endl; + cout << wxT("MEMO DATA TYPE: ") << typeInfMemo.TypeName << endl; cout << endl; #endif @@ -2286,6 +2321,9 @@ bool wxDb::ExecSql(const wxString &pSqlStmt, wxDbColInf** columns, short& numcol case SQL_CHAR: pColInf[colNum].dbDataType = DB_DATA_TYPE_VARCHAR; break; + case SQL_LONGVARCHAR: + pColInf[colNum].dbDataType = DB_DATA_TYPE_MEMO; + break; case SQL_TINYINT: case SQL_SMALLINT: case SQL_INTEGER: @@ -3069,6 +3107,9 @@ wxDbColInf *wxDb::GetColumns(const wxString &tableName, int *numCols, const wxCh case SQL_CHAR: colInf[colNo].dbDataType = DB_DATA_TYPE_VARCHAR; break; + case SQL_LONGVARCHAR: + colInf[colNo].dbDataType = DB_DATA_TYPE_MEMO; + break; case SQL_TINYINT: case SQL_SMALLINT: case SQL_INTEGER: diff --git a/src/common/dbtable.cpp b/src/common/dbtable.cpp index f32954f688..0e781f19a3 100644 --- a/src/common/dbtable.cpp +++ b/src/common/dbtable.cpp @@ -413,11 +413,13 @@ void wxDbTable::setCbValueForColumn(int columnIndex) switch(colDefs[columnIndex].DbDataType) { case DB_DATA_TYPE_VARCHAR: + case DB_DATA_TYPE_MEMO: if (colDefs[columnIndex].Null) colDefs[columnIndex].CbValue = SQL_NULL_DATA; else colDefs[columnIndex].CbValue = SQL_NTS; break; + break; case DB_DATA_TYPE_INTEGER: if (colDefs[columnIndex].Null) colDefs[columnIndex].CbValue = SQL_NULL_DATA; @@ -484,6 +486,11 @@ bool wxDbTable::bindParams(bool forUpdate) precision = colDefs[i].SzDataObj; scale = 0; break; + case DB_DATA_TYPE_MEMO: + fSqlType = pDb->GetTypeInfMemo().FsqlType; + precision = colDefs[i].SzDataObj; + scale = 0; + break; case DB_DATA_TYPE_INTEGER: fSqlType = pDb->GetTypeInfInteger().FsqlType; precision = pDb->GetTypeInfInteger().Precision; @@ -1414,6 +1421,9 @@ bool wxDbTable::CreateTable(bool attemptDrop) case DB_DATA_TYPE_VARCHAR: cout << pDb->GetTypeInfVarchar().TypeName << wxT("(") << (int)(colDefs[i].SzDataObj / sizeof(wxChar)) << wxT(")"); break; + case DB_DATA_TYPE_MEMO: + cout << pDb->GetTypeInfMemo().TypeName; + break; case DB_DATA_TYPE_INTEGER: cout << pDb->GetTypeInfInteger().TypeName; break; @@ -1455,6 +1465,9 @@ bool wxDbTable::CreateTable(bool attemptDrop) case DB_DATA_TYPE_VARCHAR: sqlStmt += pDb->GetTypeInfVarchar().TypeName; break; + case DB_DATA_TYPE_MEMO: + sqlStmt += pDb->GetTypeInfMemo().TypeName; + break; case DB_DATA_TYPE_INTEGER: sqlStmt += pDb->GetTypeInfInteger().TypeName; break; @@ -2349,6 +2362,11 @@ wxDbColDataPtr* wxDbTable::SetColDefs(wxDbColInf *pColInfs, UWORD numCols) pColDataPtrs[index].SzDataObj = pColInfs[index].bufferSize+(1*sizeof(wxChar)); pColDataPtrs[index].SqlCtype = SQL_C_WXCHAR; break; + case DB_DATA_TYPE_MEMO: + pColDataPtrs[index].PtrDataObj = new wxChar[pColInfs[index].bufferSize+(1*sizeof(wxChar))]; + pColDataPtrs[index].SzDataObj = pColInfs[index].bufferSize+(1*sizeof(wxChar)); + pColDataPtrs[index].SqlCtype = SQL_C_WXCHAR; + break; case DB_DATA_TYPE_INTEGER: // Can be long or short if (pColInfs[index].bufferSize == sizeof(long)) -- 2.45.2