Modified:
MYSQLPlus/MYSQLPlusLib/MDescriptorRecord.h
MYSQLPlus/MYSQLPlusLib/MResult.cpp
MYSQLPlus/MYSQLPlusLib/MResult.h
MYSQLPlus/MYSQLPlusLib/MResultStmt.cpp
MYSQLPlus/MYSQLPlusLib/MResultStmt.h
MYSQLPlus/MYSQLPlusLib/MStatement.cpp
Log:
Modified: MYSQLPlus/MYSQLPlusLib/MDescriptorRecord.h
===================================================================
--- MYSQLPlus/MYSQLPlusLib/MDescriptorRecord.h 2006-05-15 20:39:22 UTC (rev 242)
+++ MYSQLPlus/MYSQLPlusLib/MDescriptorRecord.h 2006-05-16 14:11:07 UTC (rev 243)
@@ -133,6 +133,9 @@
virtual SQLSMALLINT getUnsigned();
virtual SQLSMALLINT getUpdatable();
+ /* getters */
+ int getTypeNative();
+
/* doers */
virtual SQLRETURN doUnbind();
virtual SQLRETURN doConsistencyCheck();
Modified: MYSQLPlus/MYSQLPlusLib/MResult.cpp
===================================================================
--- MYSQLPlus/MYSQLPlusLib/MResult.cpp 2006-05-15 20:39:22 UTC (rev 242)
+++ MYSQLPlus/MYSQLPlusLib/MResult.cpp 2006-05-16 14:11:07 UTC (rev 243)
@@ -73,6 +73,31 @@
MYODBCDbgReturn3( "%d", nState );
}
+/*!
+ \internal
+ \brief
+
+ \param nColumnNumber
+ \param nTargetType
+ \param pTargetValue
+ \param nBufferLength
+ \param pnLength
+ \param pnIndicator
+ \param pDescriptorRecord IRD, ARD or APD descriptor record to be used for
precision and scale in SQL_NUMERIC_STRUCT.
+ - IRD if we are a plain SQLGetData call. This means we
use precision and scale found in
+ the metadata.
+ - ARD if we are being called to get data for a bound
column. This means we use precision and
+ scale specified by app for bind.
+ - APD if we are being called to get data for a bound
parameter. This means we use precision and
+ scale specified by app for bind.
+
+ \return SQLRETURN
+
+ \retval SQL_SUCCESS
+ \retval SQL_SUCCESS_WITH_INFO
+ \retval SQL_NO_DATA
+ \retval SQL_ERROR
+*/
SQLRETURN MResult::getData( SQLUSMALLINT nColumnNumber, SQLSMALLINT nTargetType,
SQLPOINTER pTargetValue, SQLINTEGER nBufferLength, SQLINTEGER *pnLength, SQLINTEGER
*pnIndicator )
{
MYODBCDbgEnter();
@@ -99,203 +124,94 @@
/* get data and data length, convert data as needed */
switch ( nTargetType )
{
- case SQL_C_CHAR:
+ /*!
+ \internal ODBC RULE
+
+ If TargetType is SQL_ARD_TYPE, the driver uses the type identifier specified
in the
+ SQL_DESC_CONCISE_TYPE field of the ARD.
+ */
+ case SQL_ARD_TYPE:
{
- if ( !variantData.canConvert<QString>() )
- MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_07006
) );
- QString stringData = variantData.toString();
- MYODBCC::doStrNCpy( (SQLWCHAR*)pTargetValue, nBufferLength /
sizeof(SQLWCHAR), stringData.utf16() );
- if ( pnLength ) *pnLength = stringData.length() * sizeof(SQLWCHAR);
+ if ( nColumnNumber > getAppRowDesc()->getCount() )
+ {
+ }
+ MDescriptorRecord *pDescriptorRecordARD = getAppRowDesc()->getRecord(
nColumnNumber );
+ MYODBCDbgReturn( getData( nColumnNumber,
pDescriptorRecordARD->getConciseType(), pTargetValue, nBufferLength, pnLength,
pnIndicator, pDescriptorRecord ) );
}
break;
- case SQL_C_SSHORT:
+
+ /*!
+ \internal ODBC RULE
+
+ If it is SQL_C_DEFAULT, the driver selects the default C data type based on
the SQL
+ data type of the source.
+ */
+ case SQL_C_DEFAULT:
{
- if ( !variantData.canConvert<short int>() )
- MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_07006
) );
- *((short int*)pTargetValue) = (short int)variantData.toInt();
- if ( pnLength ) *pnLength = sizeof(short int);
}
- break;
- case SQL_C_USHORT:
- {
- if ( !variantData.canConvert<unsigned short int>() )
- MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_07006
) );
- *((unsigned short int*)pTargetValue) = (unsigned short
int)variantData.toUInt();
- if ( pnLength ) *pnLength = sizeof(unsigned short int);
- }
- break;
+
+ MYODBCDbgReturn( getData( SQLUSMALLINT nColumnNumber, SQLSMALLINT
nTargetType, SQLPOINTER pTargetValue, SQLINTEGER nBufferLength, SQLINTEGER *pnLength,
SQLINTEGER *pnIndicator ) );
+
+ case SQL_C_CHAR:
+ MYODBCDbgReturn( getData( variantData, (SQLWCHAR *)pTargetValue,
nBufferLength * sizeof(SQLWCHAR), SQLINTEGER pnLength ) );
+
+ case SQL_C_SSHORT:
+ MYODBCDbgReturn( getData( variantData, (short int *)pTargetValue, pnLength )
);
+
+ case SQL_C_USHORT:
+ MYODBCDbgReturn( getData( variantData, (unsigned short int *)pTargetValue,
pnLength ) );
+
case SQL_C_SLONG:
- {
- if ( !variantData.canConvert<long int>() )
- MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_07006
) );
- *((long int*)pTargetValue) = (long int)variantData.toLongLong();
- if ( pnLength ) *pnLength = sizeof(long int);
- }
- break;
+ MYODBCDbgReturn( getData( variantData, (long int *)pTargetValue, pnLength )
);
+
case SQL_C_ULONG:
- {
- if ( !variantData.canConvert<unsigned long int>() )
- MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_07006
) );
- *((unsigned long int*)pTargetValue) = (unsigned long
int)variantData.toULongLong();
- if ( pnLength ) *pnLength = sizeof(unsigned long int);
- }
- break;
+ MYODBCDbgReturn( getData( variantData, (unsigned long int *)pTargetValue,
pnLength ) );
+
case SQL_C_FLOAT:
- {
- if ( !variantData.canConvert<float>() )
- MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_07006
) );
- *((float *)pTargetValue) = (float)variantData.toDouble();
- if ( pnLength ) *pnLength = sizeof(float);
- }
- break;
+ MYODBCDbgReturn( getData( variantData, (float *)pTargetValue, pnLength ) );
+
case SQL_C_DOUBLE:
- {
- if ( !variantData.canConvert<double>() )
- MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_07006
) );
- *((double *)pTargetValue) = (double)variantData.toDouble();
- if ( pnLength ) *pnLength = sizeof(double);
- }
- break;
+ MYODBCDbgReturn( getData( variantData, (double *)pTargetValue, pnLength ) );
+
case SQL_C_BIT:
- {
- if ( !variantData.canConvert<unsigned char>() )
- MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_07006
) );
- *((unsigned char *)pTargetValue) = variantData.toInt();
- if ( pnLength ) *pnLength = sizeof(unsigned char);
- }
- break;
+ MYODBCDbgReturn( getData( variantData, (unsigned char *)pTargetValue,
pnLength ) );
+
case SQL_C_STINYINT:
- {
- if ( !variantData.canConvert<char>() )
- MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_07006
) );
- *((char *)pTargetValue) = variantData.toInt();
- if ( pnLength ) *pnLength = sizeof(char);
- }
- break;
+ MYODBCDbgReturn( getData( variantData, (char *)pTargetValue, pnLength ) );
+
case SQL_C_UTINYINT:
- {
- if ( !variantData.canConvert<unsigned char>() )
- MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_07006
) );
- *((unsigned char *)pTargetValue) = variantData.toUInt();
- if ( pnLength ) *pnLength = sizeof(unsigned char);
- }
- break;
+ MYODBCDbgReturn( getData( variantData, (unsigned char *)pTargetValue,
pnLength ) );
+
case SQL_C_SBIGINT:
- {
- if ( !variantData.canConvert<qint64>() )
- MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_07006
) );
- *((qint64*)pTargetValue) = (qint64)variantData.toLongLong();
- if ( pnLength ) *pnLength = sizeof(qint64);
- }
- break;
+ MYODBCDbgReturn( getData( variantData, (qint64 *)pTargetValue, pnLength ) );
+
case SQL_C_UBIGINT:
- {
- if ( !variantData.canConvert<quint64>() )
- MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_07006
) );
- *((quint64*)pTargetValue) = (quint64)variantData.toULongLong();
- if ( pnLength ) *pnLength = sizeof(quint64);
- }
- break;
+ MYODBCDbgReturn( getData( variantData, (quint64 *)pTargetValue, pnLength ) );
+
case SQL_C_BINARY:
- {
- QByteArray bytearray = variantData.toByteArray();
+ MYODBCDbgReturn( getData( variantData, pTargetValue, nBufferLength, pnLength
) );
- MYODBCC::doMemCpy( pTargetValue, bytearray.constData(), nBufferLength );
- if ( pnLength ) *pnLength = bytearray.size();
- }
- break;
case SQL_C_TYPE_DATE:
- {
- SQL_DATE_STRUCT *pdate = (SQL_DATE_STRUCT *)pTargetValue;
+ MYODBCDbgReturn( getData( variantData, (SQL_DATE_STRUCT *)pTargetValue,
pnLength ) );
- if ( !variantData.canConvert<QDate>() )
- MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_07006
) );
- QDate d = variantData.toDate();
- pdate->day = d.day();
- pdate->month = d.month();
- pdate->year = d.year();
- if ( pnLength ) *pnLength = sizeof(SQL_DATE_STRUCT);
- }
- break;
case SQL_C_TYPE_TIME:
- {
- SQL_TIME_STRUCT *ptime = (SQL_TIME_STRUCT *)pTargetValue;
+ MYODBCDbgReturn( getData( variantData, (SQL_TIME_STRUCT *)pTargetValue,
pnLength ) );
- if ( !variantData.canConvert<QTime>() )
- MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_07006
) );
- QTime t = variantData.toTime();
- ptime->hour = t.hour();
- ptime->minute = t.minute();
- ptime->second = t.second();
- if ( pnLength ) *pnLength = sizeof(SQL_TIME_STRUCT);
- }
- break;
case SQL_C_TYPE_TIMESTAMP:
- {
- SQL_TIMESTAMP_STRUCT *p = (SQL_TIMESTAMP_STRUCT *)pTargetValue;
+ MYODBCDbgReturn( getData( variantData, (SQL_TIMESTAMP_STRUCT *)pTargetValue,
pnLength ) );
- if ( !variantData.canConvert<QDateTime>() )
- MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_07006
) );
- QDateTime t = variantData.toDateTime();
- p->day = t.date().day();
- p->fraction = t.time().msec(); /*! \todo fraction is not same as
msec - look into it */
- p->hour = t.time().hour();
- p->minute = t.time().minute();
- p->month = t.date().month();
- p->second = t.time().second();
- p->year = t.date().year();
- if ( pnLength ) *pnLength = sizeof(SQL_TIMESTAMP_STRUCT);
- }
- break;
case SQL_C_NUMERIC:
{
- SQL_NUMERIC_STRUCT *pNumericStruct = (SQL_NUMERIC_STRUCT
*)pTargetValue;
- MDescriptorRecord * pDescriptorRecord = getImpRowDesc()->getRecord(
nColumn );
+ SQL_NUMERIC_STRUCT *pNumeric = (SQL_NUMERIC_STRUCT *)pTargetValue;
- /*!
- \internal ODBC RULE
+ pNumeric->precision = 10; /* default precision */
+ pNumeric->scale = 0; /* default scale */
- The precision and scale fields of the SQL_C_NUMERIC data type are
never used for input from
- an application, only for output from the driver to the application.
When the driver writes a
- numeric value into the SQL_NUMERIC_STRUCT, it will use its own
driver-specific default as the
- value for the precision field, and it will use the value in the
SQL_DESC_SCALE field of the
- application descriptor (which defaults to 0) for the scale field. An
application can provide
- its own values for precision and scale by setting the
SQL_DESC_PRECISION and SQL_DESC_SCALE
- fields of the application descriptor.
- */
- pNumericStruct->precision = pDescriptorRecord->getPrecision();
- pNumericStruct->scale = pDescriptorRecord->getScale();
-
- /*!
- \internal ODBC RULE
-
- The sign field is 1 if positive, 0 if negative.
- */
- if ( pDescriptorRecord->getUnsigned() )
- pNumericStruct->sign = 1;
- else
- pNumericStruct->sign = ?;
-
- /*!
- \internal ODBC RULE
-
- A number is stored in the val field of the SQL_NUMERIC_STRUCT
structure as a scaled integer,
- in little endian mode (the leftmost byte being the least-significant
byte). For example, the
- number 10.001 base 10, with a scale of 4, is scaled to an integer of
100010. Because this is
- 186AA in hexadecimal format, the value in SQL_NUMERIC_STRUCT would be
"AA 86 01 00 00 ... 00",
- with the number of bytes defined by the SQL_MAX_NUMERIC_LEN #define.
- */
- pNumericStruct->val = ?;
-
- switch ()
- {
- }
-
- if ( pnLength ) *pnLength = sizeof(SQL_NUMERIC_STRUCT);
+ MYODBCDbgReturn( getData( variantData, pNumeric, pnLength ) );
}
break;
+
case SQL_C_GUID:
- case SQL_C_DEFAULT:
case SQL_C_INTERVAL_MONTH:
case SQL_C_INTERVAL_YEAR:
case SQL_C_INTERVAL_YEAR_TO_MONTH:
@@ -309,7 +225,6 @@
case SQL_C_INTERVAL_HOUR_TO_MINUTE:
case SQL_C_INTERVAL_HOUR_TO_SECOND:
case SQL_C_INTERVAL_MINUTE_TO_SECOND:
- break;
default:
MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_HY000, 0,
tr("unsupported concise type") ) );
}
@@ -317,6 +232,31 @@
MYODBCDbgReturn( nReturn );
}
+/*!
+ \brief This gets column data from the drivers row buffers.
+
+ \param nColumn The column we are dealing with.
+ \param pDescriptorRecord This is a bound ARD.
+
+ \return SQLRETURN
+
+ \sa getData
+*/
+SQLRETURN MResult::getData( SQLUSMALLINT nColumn, MDescriptorRecord *pDescriptorRecord )
+{
+ MYODBCDbgEnter();
+
+ Q_ASSERT( !pDescriptorRecord );
+
+ MYODBCDbgReturn( getData( nColumn,
+ pDescriptorRecord->getConciseType(),
+ pDescriptorRecord->getDataPtr(),
+ pDescriptorRecord->getOctetLength(),
+ pDescriptorRecord->getOctetLengthPtr(),
+ pDescriptorRecord->getIndicatorPtr(),
+ pDescriptorRecord ) );
+}
+
BOOLEAN MResult::isBuffered()
{
MYODBCDbgEnter();
@@ -406,28 +346,274 @@
MYODBCDbgReturn3( "%p", getStatement()->getImpRowDesc() );
}
-/*!
- \brief This gets column data from the drivers row buffers.
- \param nColumn The column we are dealing with.
- \param pDescriptorRecord This is a bound ARD.
+SQLRETURN getData( const QVariant &variantData, SQLWCHAR *psTarget, SQLINTEGER
nCharsMax, SQLINTEGER *nCharsAvailable )
+{
+ MYODBCDbgEnter();
- \return SQLRETURN
+ if ( !variantData.canConvert<QString>() )
+ MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_07006 ) );
+ QString stringData = variantData.toString();
+ MYODBCC::doStrNCpy( psTarget, nCharsMax, stringData.utf16() );
+ if ( nCharsAvailable ) *nCharsAvailable = stringData.length();
- \sa getData
-*/
-SQLRETURN MResult::getData( SQLUSMALLINT nColumn, MDescriptorRecordARD *pDescriptorRecord
)
+ MYODBCDbgReturn( SQL_SUCCESS );
+}
+
+SQLRETURN getData( const QVariant &variantData, short int *pnTarget, SQLINTEGER
*pnLength );
{
MYODBCDbgEnter();
- Q_ASSERT( !pDescriptorRecord );
+ if ( !variantData.canConvert<short int>() )
+ MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_07006 ) );
+ *pnTarget = (short int)variantData.toInt();
+ if ( pnLength ) *pnLength = sizeof(short int);
- MYODBCDbgReturn( getData( nColumn,
- pDescriptorRecord->getConciseType(),
- pDescriptorRecord->getDataPtr(),
- pDescriptorRecord->getOctetLength(),
- pDescriptorRecord->getOctetLengthPtr(),
- pDescriptorRecord->getIndicatorPtr() ) );
+ MYODBCDbgReturn( SQL_SUCCESS );
}
+SQLRETURN getData( const QVariant &variantData, unsigned short int *pnTarget,
SQLINTEGER *pnLength );
+{
+ MYODBCDbgEnter();
+ if ( !variantData.canConvert<unsigned short int>() )
+ MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_07006 ) );
+ *pnTarget = (unsigned short int)variantData.toUInt();
+ if ( pnLength ) *pnLength = sizeof(unsigned short int);
+
+ MYODBCDbgReturn( SQL_SUCCESS );
+}
+
+SQLRETURN getData( const QVariant &variantData, long int *pnTarget, SQLINTEGER
*pnLength );
+{
+ MYODBCDbgEnter();
+
+ if ( !variantData.canConvert<long int>() )
+ MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_07006 ) );
+ *pnTarget = (long int)variantData.toLongLong();
+ if ( pnLength ) *pnLength = sizeof(long int);
+
+ MYODBCDbgReturn( SQL_SUCCESS );
+}
+
+SQLRETURN getData( const QVariant &variantData, unsigned long int *pnTarget,
SQLINTEGER *pnLength );
+{
+ MYODBCDbgEnter();
+
+ if ( !variantData.canConvert<unsigned long int>() )
+ MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_07006 ) );
+ *pTarget = (unsigned long int)variantData.toULongLong();
+ if ( pnLength ) *pnLength = sizeof(unsigned long int);
+
+ MYODBCDbgReturn( SQL_SUCCESS );
+}
+
+SQLRETURN getData( const QVariant &variantData, float *pnTarget, SQLINTEGER *pnLength
);
+{
+ MYODBCDbgEnter();
+
+ if ( !variantData.canConvert<float>() )
+ MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_07006 ) );
+ *pnTarget = (float)variantData.toDouble();
+ if ( pnLength ) *pnLength = sizeof(float);
+
+ MYODBCDbgReturn( SQL_SUCCESS );
+}
+
+SQLRETURN getData( const QVariant &variantData, double *pnTarget, SQLINTEGER
*pnLength );
+{
+ MYODBCDbgEnter();
+
+ if ( !variantData.canConvert<double>() )
+ MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_07006 ) );
+ *pnTarget = (double)variantData.toDouble();
+ if ( pnLength ) *pnLength = sizeof(double);
+
+ MYODBCDbgReturn( SQL_SUCCESS );
+}
+
+SQLRETURN getData( const QVariant &variantData, char *pnTarget, SQLINTEGER *pnLength
);
+{
+ MYODBCDbgEnter();
+
+ if ( !variantData.canConvert<char>() )
+ MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_07006 ) );
+ *pnTarget = variantData.toInt();
+ if ( pnLength ) *pnLength = sizeof(char);
+
+ MYODBCDbgReturn( SQL_SUCCESS );
+}
+
+SQLRETURN getData( const QVariant &variantData, unsigned char *pnTarget, SQLINTEGER
*pnLength );
+{
+ MYODBCDbgEnter();
+
+ if ( !variantData.canConvert<unsigned char>() )
+ MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_07006 ) );
+ *pnTarget = variantData.toInt();
+ if ( pnLength ) *pnLength = sizeof(unsigned char);
+
+ MYODBCDbgReturn( SQL_SUCCESS );
+}
+
+SQLRETURN getData( const QVariant &variantData, qint64 *pnTarget, SQLINTEGER
*pnLength );
+{
+ MYODBCDbgEnter();
+
+ if ( !variantData.canConvert<qint64>() )
+ MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_07006 ) );
+ *pnTarget = (qint64)variantData.toLongLong();
+ if ( pnLength ) *pnLength = sizeof(qint64);
+
+ MYODBCDbgReturn( SQL_SUCCESS );
+}
+
+SQLRETURN getData( const QVariant &variantData, quint64 *pnTarget, SQLINTEGER
*pnLength );
+{
+ MYODBCDbgEnter();
+
+ if ( !variantData.canConvert<quint64>() )
+ MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_07006 ) );
+ *pnTarget = (quint64)variantData.toLongLong();
+ if ( pnLength ) *pnLength = sizeof(quint64);
+
+ MYODBCDbgReturn( SQL_SUCCESS );
+}
+
+SQLRETURN getData( const QVariant &variantData, SQLPOINTER pTarget, SQLINTEGER
nBytesMax, SQLINTEGER *pnBytesAvailable );
+{
+ MYODBCDbgEnter();
+
+ QByteArray bytearray = variantData.toByteArray();
+
+ MYODBCC::doMemCpy( pTarget, bytearray.constData(), nBytesMax );
+ if ( pnBytesAvailable ) *pnBytesAvailable = bytearray.size();
+
+ MYODBCDbgReturn( SQL_SUCCESS );
+}
+
+SQLRETURN getData( const QVariant &variantData, SQL_DATE_STRUCT *pTarget, SQLINTEGER
*pnLength );
+{
+ MYODBCDbgEnter();
+
+ if ( !variantData.canConvert<QDate>() )
+ MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_07006 ) );
+ QDate d = variantData.toDate();
+ pTarget->day = d.day();
+ pTarget->month = d.month();
+ pTarget->year = d.year();
+ if ( pnLength ) *pnLength = sizeof(SQL_DATE_STRUCT);
+
+ MYODBCDbgReturn( SQL_SUCCESS );
+}
+
+SQLRETURN getData( const QVariant &variantData, SQL_TIME_STRUCT *pTarget, SQLINTEGER
*pnLength );
+{
+ MYODBCDbgEnter();
+
+ if ( !variantData.canConvert<QTime>() )
+ MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_07006 ) );
+ QTime t = variantData.toTime();
+ pTarget->hour = t.hour();
+ pTarget->minute = t.minute();
+ pTarget->second = t.second();
+ if ( pnLength ) *pnLength = sizeof(SQL_TIME_STRUCT);
+
+ MYODBCDbgReturn( SQL_SUCCESS );
+}
+
+SQLRETURN getData( const QVariant &variantData, SQL_TIMESTAMP_STRUCT *pTarget,
SQLINTEGER *pnLength );
+{
+ MYODBCDbgEnter();
+
+ if ( !variantData.canConvert<QDateTime>() )
+ MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_07006 ) );
+ QDateTime t = variantData.toDateTime();
+ pTarget->day = t.date().day();
+ pTarget->fraction = t.time().msec(); /*! \todo fraction is not same as msec -
look into it */
+ pTarget->hour = t.time().hour();
+ pTarget->minute = t.time().minute();
+ pTarget->month = t.date().month();
+ pTarget->second = t.time().second();
+ pTarget->year = t.date().year();
+ if ( pnLength ) *pnLength = sizeof(SQL_TIMESTAMP_STRUCT);
+
+ MYODBCDbgReturn( SQL_SUCCESS );
+}
+
+SQLRETURN getData( const QVariant &variantData, SQL_NUMERIC_STRUCT *pTarget,
SQLINTEGER *pnLength );
+{
+ MYODBCDbgEnter();
+
+ SQL_NUMERIC_STRUCT *pNumericStruct = (SQL_NUMERIC_STRUCT *)pTargetValue;
+
+ /*!
+ \internal ODBC RULE
+
+ The precision and scale fields of the SQL_C_NUMERIC data type are never used for
input from
+ an application, only for output from the driver to the application. When the
driver writes a
+ numeric value into the SQL_NUMERIC_STRUCT, it will use its own driver-specific
default as the
+ value for the precision field, and it will use the value in the SQL_DESC_SCALE
field of the
+ application descriptor (which defaults to 0) for the scale field. An application
can provide
+ its own values for precision and scale by setting the SQL_DESC_PRECISION and
SQL_DESC_SCALE
+ fields of the application descriptor.
+
+ In otherwords...
+
+ IF GetData THEN
+ getImpRowDesc()->getRecord( nColumn )->getPrecision();
+ getImpRowDesc()->getRecord( nColumn )->getScale();
+ ELIF BoundColumn THEN
+ getAppRowDesc()->getRecord( nColumn )->getPrecision();
+ getAppRowDesc()->getRecord( nColumn )->getScale();
+ ELIF BoundParam THEN
+ getAppParamDesc()->getRecord( nColumn )->getPrecision();
+ getAppParamDesc()->getRecord( nColumn )->getScale();
+ ENDIF
+
+ We assume caller has given as the proper descripor record!!
+ */
+ pNumericStruct->precision = pDescriptorRecord->getPrecision();
+ pNumericStruct->scale = pDescriptorRecord->getScale();
+
+ /*!
+ \internal ODBC RULE
+
+ A number is stored in the val field of the SQL_NUMERIC_STRUCT structure as a
scaled integer,
+ in little endian mode (the leftmost byte being the least-significant byte). For
example, the
+ number 10.001 base 10, with a scale of 4, is scaled to an integer of 100010.
Because this is
+ 186AA in hexadecimal format, the value in SQL_NUMERIC_STRUCT would be "AA 86 01
00 00 ... 00",
+ with the number of bytes defined by the SQL_MAX_NUMERIC_LEN #define.
+ */
+ int nScaledInteger = 0;
+
+ memset( pNumericStruct->val, 0, SQL_MAX_NUMERIC_LEN );
+
+ if ( pDescriptorRecord->className() == "MDescriptor" )
+ {
+ }
+
+ if ( !variantData.canConvert<double>() )
+ MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_07006 ) );
+ *((double *)pNumericStruct->val) = (double)variantData.toDouble();
+ if ( pnLength ) *pnLength = sizeof(SQL_NUMERIC_STRUCT);
+
+ /*!
+ \internal ODBC RULE
+
+ The sign field is 1 if positive, 0 if negative.
+
+ \note
+
+ The ODBC 3.0 spec required drivers to return the sign as 1 for positive numbers
and 2 for
+ negative number. This was changed in the ODBC 3.5 spec to return 0 for negative
instead of 2.
+ */
+ if ( *((double *)pNumericStruct->val) < 0 )
+ pNumericStruct->sign = 0;
+ else
+ pNumericStruct->sign = 1;
+
+ MYODBCDbgReturn( SQL_SUCCESS );
+}
+
+
Modified: MYSQLPlus/MYSQLPlusLib/MResult.h
===================================================================
--- MYSQLPlus/MYSQLPlusLib/MResult.h 2006-05-15 20:39:22 UTC (rev 242)
+++ MYSQLPlus/MYSQLPlusLib/MResult.h 2006-05-16 14:11:07 UTC (rev 243)
@@ -85,8 +85,26 @@
MDescriptor * getAppRowDesc();
MDescriptor * getImpParamDesc();
MDescriptor * getImpRowDesc();
- SQLRETURN getData( SQLUSMALLINT nColumn, MDescriptorRecordARD
*pDescriptorRecord );
+ SQLRETURN getData( SQLUSMALLINT nColumn, MDescriptorRecord *pDescriptorRecord
); /* MDescriptorRecord needs to be a MDescriptorRecordARD or MDescriptorRecordAPD */
+
+ SQLRETURN getData( const QVariant &variantData, SQLWCHAR *psTarget,
SQLINTEGER nCharsMax, SQLINTEGER *nCharsAvailable );
+ SQLRETURN getData( const QVariant &variantData, short int *pnTarget,
SQLINTEGER *pnLength );
+ SQLRETURN getData( const QVariant &variantData, unsigned short int
*pnTarget, SQLINTEGER *pnLength );
+ SQLRETURN getData( const QVariant &variantData, long int *pnTarget,
SQLINTEGER *pnLength );
+ SQLRETURN getData( const QVariant &variantData, unsigned long int
*pnTarget, SQLINTEGER *pnLength );
+ SQLRETURN getData( const QVariant &variantData, float *pnTarget, SQLINTEGER
*pnLength );
+ SQLRETURN getData( const QVariant &variantData, double *pnTarget,
SQLINTEGER *pnLength );
+ SQLRETURN getData( const QVariant &variantData, char *pnTarget, SQLINTEGER
*pnLength );
+ SQLRETURN getData( const QVariant &variantData, unsigned char *pnTarget,
SQLINTEGER *pnLength );
+ SQLRETURN getData( const QVariant &variantData, qint64 *pnTarget,
SQLINTEGER *pnLength );
+ SQLRETURN getData( const QVariant &variantData, quint64 *pnTarget,
SQLINTEGER *pnLength );
+ SQLRETURN getData( const QVariant &variantData, SQLPOINTER pTarget,
SQLINTEGER nBytesMax, SQLINTEGER *pnBytesAvailable );
+ SQLRETURN getData( const QVariant &variantData, SQL_DATE_STRUCT *pTarget,
SQLINTEGER *pnLength );
+ SQLRETURN getData( const QVariant &variantData, SQL_TIME_STRUCT *pTarget,
SQLINTEGER *pnLength );
+ SQLRETURN getData( const QVariant &variantData, SQL_TIMESTAMP_STRUCT
*pTarget, SQLINTEGER *pnLength );
+ SQLRETURN getData( const QVariant &variantData, SQL_NUMERIC_STRUCT
*pTarget, SQLINTEGER *pnLength );
+
/* doers */
virtual SQLRETURN doStateRollBack( STATE nState ) = 0;
Modified: MYSQLPlus/MYSQLPlusLib/MResultStmt.cpp
===================================================================
--- MYSQLPlus/MYSQLPlusLib/MResultStmt.cpp 2006-05-15 20:39:22 UTC (rev 242)
+++ MYSQLPlus/MYSQLPlusLib/MResultStmt.cpp 2006-05-16 14:11:07 UTC (rev 243)
@@ -276,6 +276,8 @@
QTime( pdatetime->hour,
pdatetime->minute, pdatetime->second, pdatetime->second_part ) ) );
}
break;
+ case MYSQL_TYPE_DECIMAL: /* DECIMAL is not packed - just a string
*/
+ case MYSQL_TYPE_NEWDECIMAL: /* DECIMAL is not packed - just a string
*/
case MYSQL_TYPE_VAR_STRING:
case MYSQL_TYPE_TINY_BLOB:
case MYSQL_TYPE_BLOB:
@@ -1097,7 +1099,7 @@
if ( pDescriptorRecord->getDataPtr() )
{
- SQLRETURN nReturn = getData( nColumn, pDescriptorRecord );
+ SQLRETURN nReturn = getData( nColumn, pDescriptor );
if ( nReturn != SQL_SUCCESS )
MYODBCDbgReturn( nReturn );
}
@@ -1121,7 +1123,7 @@
- mysql server does not understand all ODBC data types such as
SQL_NUMERIC_STRUCT
- in ODBC one can bind/unbind at anytime while in mysql one is limited to
when bind/unbind
can occur
- - we can not chunk data when using mysql_stmt_bind_result()
+ - we can not chunk data when using mysql_stmt_bind_result() (and we hope to
do chunking)
\return SQLRETURN
@@ -1168,6 +1170,13 @@
MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_HY000, 0,
tr("Failed to store field descriptor information.") ) );
}
+ /*!
+ \internal
+ \todo
+
+ - reduce memory usage for data
+ - consider ways to chunk data to avoid allocate of max length
+ */
/* init bind for field */
pbindColumns[nField].buffer_type = pField->type;
pbindColumns[nField].buffer_length = pField->max_length + 1;
Modified: MYSQLPlus/MYSQLPlusLib/MResultStmt.h
===================================================================
--- MYSQLPlus/MYSQLPlusLib/MResultStmt.h 2006-05-15 20:39:22 UTC (rev 242)
+++ MYSQLPlus/MYSQLPlusLib/MResultStmt.h 2006-05-16 14:11:07 UTC (rev 243)
@@ -78,6 +78,7 @@
BOOLEAN isDirty();
protected:
+
/* doers */
SQLRETURN doStateRollBack( STATE nState );
Modified: MYSQLPlus/MYSQLPlusLib/MStatement.cpp
===================================================================
--- MYSQLPlus/MYSQLPlusLib/MStatement.cpp 2006-05-15 20:39:22 UTC (rev 242)
+++ MYSQLPlus/MYSQLPlusLib/MStatement.cpp 2006-05-16 14:11:07 UTC (rev 243)
@@ -430,7 +430,7 @@
/* get data */
SQLINTEGER nLength;
SQLINTEGER nIndicator;
- SQLRETURN nReturn = pResult->getData( nColumnNumber, nTargetType, pTargetValue,
nBufferLength, &nLength, &nIndicator );
+ SQLRETURN nReturn = pResult->getData( nColumnNumber, nTargetType, pTargetValue,
nBufferLength, &nLength, &nIndicator, getImpRowDesc()->getRecord(
nColumnNumber ) );
if ( !SQL_SUCCEEDED(nReturn) )
MYODBCDbgReturn( nReturn );
| Thread |
|---|
| • Connector/ODBC 5 commit: r243 - MYSQLPlus/MYSQLPlusLib | pharvey | 16 May |