List:Commits« Previous MessageNext Message »
From:pharvey Date:January 16 2006 4:56am
Subject:Connector/ODBC 5 commit: r41 - in MYODBCRes: MYODBCResLib include
View as plain text  
Added:
   MYODBCRes/MYODBCResLib/MYODBCResServer.cpp
   MYODBCRes/include/MYODBCResServer.h
Modified:
   MYODBCRes/MYODBCResLib/MYODBCResDriver.cpp
   MYODBCRes/MYODBCResLib/MYODBCResInternal.h
   MYODBCRes/MYODBCResLib/MYODBCResLib.pro
   MYODBCRes/include/MYODBCRes.h
   MYODBCRes/include/MYODBCResDriver.h
Log:
UNICODE:
- start of support for prepared statements

Modified: MYODBCRes/MYODBCResLib/MYODBCResDriver.cpp
===================================================================
--- MYODBCRes/MYODBCResLib/MYODBCResDriver.cpp	2006-01-16 04:24:28 UTC (rev 40)
+++ MYODBCRes/MYODBCResLib/MYODBCResDriver.cpp	2006-01-16 04:56:16 UTC (rev 41)
@@ -122,6 +122,13 @@
     MYODBCDbgReturn( SQL_SUCCESS );
 }
 
+SQLRETURN MYODBCResDriver::doExecute( const QString & )
+{
+    MYODBCDbgEnter();
+
+    MYODBCDbgReturn( pdia->doAppend( MYODBC_DIA_HY000, 0, "Execute a statement is not
relevant for driver generated resultsets." ) );
+}
+
 SQLRETURN MYODBCResDriver::doFirst()
 {
     MYODBCDbgEnter();
@@ -177,6 +184,13 @@
     MYODBCDbgReturn( SQL_SUCCESS );
 }
 
+SQLRETURN MYODBCResDriver::doPrepare( const QString & )
+{
+    MYODBCDbgEnter();
+
+    MYODBCDbgReturn( pdia->doAppend( MYODBC_DIA_HY000, 0, "Prepare a statement is not
relevant for driver generated resultsets." ) );
+}
+
 SQLRETURN MYODBCResDriver::doPrev()
 {
     MYODBCDbgEnter();
@@ -191,6 +205,21 @@
     MYODBCDbgReturn( SQL_SUCCESS );
 }
 
+SQLRETURN MYODBCResDriver::doSeek( qlonglong nRow )
+{
+    MYODBCDbgEnter();
+
+    if ( !isValidRow( nRow ) )
+    {
+        nRow = 0;
+        MYODBCDbgReturn( SQL_NO_DATA );
+    }
+
+    this->nRow = nRow;
+
+    MYODBCDbgReturn( SQL_SUCCESS );
+}
+
 SQLRETURN MYODBCResDriver::doSkip( qlonglong nRows )
 {
     MYODBCDbgEnter();

Modified: MYODBCRes/MYODBCResLib/MYODBCResInternal.h
===================================================================
--- MYODBCRes/MYODBCResLib/MYODBCResInternal.h	2006-01-16 04:24:28 UTC (rev 40)
+++ MYODBCRes/MYODBCResLib/MYODBCResInternal.h	2006-01-16 04:56:16 UTC (rev 41)
@@ -11,6 +11,7 @@
 #define MYODBC_RES_INTERNAL_H
 
 #include "../include/MYODBCResDriver.h"
+#include "../include/MYODBCResServer.h"
 
 #endif
 

Modified: MYODBCRes/MYODBCResLib/MYODBCResLib.pro
===================================================================
--- MYODBCRes/MYODBCResLib/MYODBCResLib.pro	2006-01-16 04:24:28 UTC (rev 40)
+++ MYODBCRes/MYODBCResLib/MYODBCResLib.pro	2006-01-16 04:56:16 UTC (rev 41)
@@ -38,9 +38,11 @@
 HEADERS		= \
 		../include/MYODBCRes.h \
 		../include/MYODBCResDriver.h \
+		../include/MYODBCResServer.h \
 		MYODBCResInternal.h
 
 SOURCES		= \
 		MYODBCRes.cpp \
-		MYODBCResDriver.cpp
+		MYODBCResDriver.cpp \
+		MYODBCResServer.cpp
 

Added: MYODBCRes/MYODBCResLib/MYODBCResServer.cpp
===================================================================
--- MYODBCRes/MYODBCResLib/MYODBCResServer.cpp	2006-01-16 04:24:28 UTC (rev 40)
+++ MYODBCRes/MYODBCResLib/MYODBCResServer.cpp	2006-01-16 04:56:16 UTC (rev 41)
@@ -0,0 +1,269 @@
+#include "MYODBCResInternal.h"
+
+MYODBCResServer::MYODBCResServer( MYODBCDia *pdia, MYODBCDes *pdesIRD, MYSQL *pmysql )
+    : MYODBCRes( pdia, pdesIRD, pmysql )
+{
+    MYODBCDbgEnter();
+
+    pstm    = mysql_stmt_init( pmysql );
+    Q_ASSERT( !pstm );
+    nRow    = 0;
+
+    MYODBCDbgReturn2();
+}
+
+MYODBCResServer::~MYODBCResServer()
+{
+    MYODBCDbgEnter();
+
+    mysql_stmt_close( pstm );
+
+    MYODBCDbgReturn2();
+}
+
++++++++++++++
+
+SQLRETURN MYODBCResServer::setData( uint nColumn, const QVariant &variantData )
+{
+    MYODBCDbgEnter();
+
+    Q_ASSERT( !isValidRow() );
+    Q_ASSERT( !isValidColumn( nColumn ) );
+    // can not write this column (and it does not really exist anyway as bookmark is row
num)
+    Q_ASSERT( nColumn == 0 ); 
+
+    listResults[ nRow - 1 ].replace( nColumn - 1, variantData );
+
+    MYODBCDbgReturn( SQL_SUCCESS );
+}
+
+SQLRETURN MYODBCResServer::setRow( qulonglong nRow )
+{
+    MYODBCDbgEnter();
+
+    Q_ASSERT( !isValidRow( nRow ) );
+
+    this->nRow = nRow;
+
+    MYODBCDbgReturn( SQL_SUCCESS );
+}
+
+SQLRETURN MYODBCResServer::getColumns( uint *pnColumns )
+{
+    MYODBCDbgEnter();
+
+    Q_ASSERT( !pnColumns );
+
+    *pnColumns = pdesIRD->getCount();
+
+    MYODBCDbgReturn( SQL_SUCCESS );
+}
+
+SQLRETURN MYODBCResServer::getData( uint nColumn, QVariant &variantData )
+{
+    MYODBCDbgEnter();
+
+    Q_ASSERT( !isValidRow() );
+    Q_ASSERT( !isValidColumn( nColumn ) );
+
+    if ( nColumn == 0 )
+        variantData = nRow; // bookmark is row num - obvious limitations apply
+    else
+        variantData = listResults[ nRow - 1 ][ nColumn - 1 ];
+
+    MYODBCDbgReturn( SQL_SUCCESS );
+}
+
+SQLRETURN MYODBCResServer::getRow( qulonglong *pnRow )
+{
+    MYODBCDbgEnter();
+
+    Q_ASSERT( !pnRow );
+
+    *pnRow = nRow;
+
+    MYODBCDbgReturn( SQL_SUCCESS );
+}
+
+SQLRETURN MYODBCResServer::getRows( qulonglong *pnRows )
+{
+    MYODBCDbgEnter();
+
+    Q_ASSERT( !pnRow );
+
+    *pnRows = listResults.count();
+
+    MYODBCDbgReturn( SQL_SUCCESS );
+}
+
+SQLRETURN MYODBCResServer::doAppend()
+{
+    MYODBCDbgEnter();
+
+    /* allocate row - no bookmark column allocated */
+    listResults.append( QVector<QVariant>( pdesIRD->getCount() - 1 ) );
+    nRow = listResults.count();
+
+    MYODBCDbgReturn( SQL_SUCCESS );
+}
+
+SQLRETURN MYODBCResServer::doClear()
+{
+    MYODBCDbgEnter();
+
+    listResults.clear();
+
+    MYODBCDbgReturn( SQL_SUCCESS );
+}
+
+SQLRETURN MYODBCResServer::doDelete()
+{
+    MYODBCDbgEnter();
+
+    Q_ASSERT( !isValidRow() );
+
+    nRow--;
+    listResults.removeAt( nRow );
+
+    MYODBCDbgReturn( SQL_SUCCESS );
+}
+
+SQLRETURN MYODBCResServer::doExecute( const QString & )
+{
+    MYODBCDbgEnter();
+
+    MYODBCDbgReturn( pdia->doAppend( MYODBC_DIA_HY000, 0, "Execute a statement is not
relevant for driver generated resultsets." ) );
+}
+
+SQLRETURN MYODBCResServer::doFirst()
+{
+    MYODBCDbgEnter();
+
+    if ( !listResults.count() )
+    {
+        nRow = 0;
+        MYODBCDbgReturn( SQL_NO_DATA );
+    }
+
+    nRow = 1;
+
+    MYODBCDbgReturn( SQL_SUCCESS );
+}
+
+SQLRETURN MYODBCResServer::doInsert()
+{
+    MYODBCDbgEnter();
+
+    if ( nRow == 0 )
+    {
+        listResults.insert( nRow, QVector<QVariant>( pdesIRD->getCount() - 1 )
);
+        doFirst();
+    }
+    else
+        listResults.insert( nRow - 1, QVector<QVariant>( pdesIRD->getCount() - 1
) );
+
+    MYODBCDbgReturn( SQL_SUCCESS );
+}
+
+SQLRETURN MYODBCResServer::doLast()
+{
+    MYODBCDbgEnter();
+
+    nRow = listResults.count();
+    if ( !isValidRow() )
+        MYODBCDbgReturn( SQL_NO_DATA );
+
+    MYODBCDbgReturn( SQL_SUCCESS );
+}
+
+SQLRETURN MYODBCResServer::doNext()
+{
+    MYODBCDbgEnter();
+
+    if ( !isValidRow() )
+        MYODBCDbgReturn( doFirst() );
+
+    nRow++;
+    if ( !isValidRow() )
+        MYODBCDbgReturn( SQL_NO_DATA );
+
+    MYODBCDbgReturn( SQL_SUCCESS );
+}
+
+SQLRETURN MYODBCResServer::doPrepare( const QString & )
+{
+    MYODBCDbgEnter();
+
+    MYODBCDbgReturn( pdia->doAppend( MYODBC_DIA_HY000, 0, "Prepare a statement is not
relevant for driver generated resultsets." ) );
+}
+
+SQLRETURN MYODBCResServer::doPrev()
+{
+    MYODBCDbgEnter();
+
+    if ( !isValidRow() )
+        MYODBCDbgReturn( doLast() );
+
+    nRow--;
+    if ( !isValidRow() )
+        MYODBCDbgReturn( SQL_NO_DATA );
+
+    MYODBCDbgReturn( SQL_SUCCESS );
+}
+
+SQLRETURN MYODBCResServer::doSeek( qlonglong nRow )
+{
+    MYODBCDbgEnter();
+
+    if ( !isValidRow( nRow ) )
+    {
+        nRow = 0;
+        MYODBCDbgReturn( SQL_NO_DATA );
+    }
+
+    this->nRow = nRow;
+
+    MYODBCDbgReturn( SQL_SUCCESS );
+}
+
+SQLRETURN MYODBCResServer::doSkip( qlonglong nRows )
+{
+    MYODBCDbgEnter();
+
+    Q_ASSERT( nRows == 0 );
+
+    if ( !isValidRow( nRow + nRows ) )
+    {
+        nRow = 0;
+        MYODBCDbgReturn( SQL_NO_DATA );
+    }
+
+    nRow += nRows;
+
+    MYODBCDbgReturn( SQL_SUCCESS );
+}
+
+bool MYODBCResServer::isValidRow()
+{
+    bool b;
+
+    MYODBCDbgEnter();
+
+    b = isValidRow( nRow );
+
+    MYODBCDbgReturn3( "%d", b );
+}
+
+bool MYODBCResServer::isValidRow( qulonglong nRow )
+{
+    bool b;
+
+    MYODBCDbgEnter();
+
+    b = ( nRow > 0 && nRow <= listResults.count() );
+
+    MYODBCDbgReturn3( "%d", b );
+}
+
+
+

Modified: MYODBCRes/include/MYODBCRes.h
===================================================================
--- MYODBCRes/include/MYODBCRes.h	2006-01-16 04:24:28 UTC (rev 40)
+++ MYODBCRes/include/MYODBCRes.h	2006-01-16 04:56:16 UTC (rev 41)
@@ -42,11 +42,14 @@
     virtual SQLRETURN doAppend() = 0;
     virtual SQLRETURN doClear() = 0;
     virtual SQLRETURN doDelete() = 0;
+    virtual SQLRETURN doExecute() = 0;
     virtual SQLRETURN doFirst() = 0;
     virtual SQLRETURN doInsert() = 0;
     virtual SQLRETURN doLast() = 0;
     virtual SQLRETURN doNext() = 0;
+    virtual SQLRETURN doPrepare( const QString &stringStatement ) = 0;
     virtual SQLRETURN doPrev() = 0;
+    virtual SQLRETURN doSeek( qlonglong nRow ) = 0;
     virtual SQLRETURN doSkip( qlonglong nRows ) = 0;
 
     virtual bool isValidColumn( uint nColumn );

Modified: MYODBCRes/include/MYODBCResDriver.h
===================================================================
--- MYODBCRes/include/MYODBCResDriver.h	2006-01-16 04:24:28 UTC (rev 40)
+++ MYODBCRes/include/MYODBCResDriver.h	2006-01-16 04:56:16 UTC (rev 41)
@@ -20,11 +20,14 @@
     virtual SQLRETURN doAppend();
     virtual SQLRETURN doClear();
     virtual SQLRETURN doDelete();
+    virtual SQLRETURN doExecute();
     virtual SQLRETURN doFirst();
     virtual SQLRETURN doInsert();
     virtual SQLRETURN doLast();
     virtual SQLRETURN doNext();
+    virtual SQLRETURN doPrepare( const QString &stringStatement );
     virtual SQLRETURN doPrev();
+    virtual SQLRETURN doSeek( qlonglong nRow );
     virtual SQLRETURN doSkip( qlonglong nRows );
 
     virtual bool isValidRow();

Added: MYODBCRes/include/MYODBCResServer.h
===================================================================
--- MYODBCRes/include/MYODBCResServer.h	2006-01-16 04:24:28 UTC (rev 40)
+++ MYODBCRes/include/MYODBCResServer.h	2006-01-16 04:56:16 UTC (rev 41)
@@ -0,0 +1,42 @@
+#ifndef MYODBC_RES_SERVER_H
+#define MYODBC_RES_SERVER_H
+
+#include "MYODBCRes.h"
+
+class MYODBCResServer : public MYODBCRes
+{
+public:
+    MYODBCResServer( MYODBCDia *pdia, MYODBCDes *pdesIRD, MYSQL *pmysql );
+    virtual ~MYODBCResServer();
+
+    virtual SQLRETURN setData( uint nColumn, const QVariant &variantData );
+    virtual SQLRETURN setRow( qulonglong nRow );
+
+    virtual SQLRETURN getColumns( uint *pnColumns );
+    virtual SQLRETURN getData( uint nColumn, QVariant &variantData );
+    virtual SQLRETURN getRow( qulonglong *pnRow );
+    virtual SQLRETURN getRows( qulonglong *pnRows );
+
+    virtual SQLRETURN doAppend();
+    virtual SQLRETURN doClear();
+    virtual SQLRETURN doDelete();
+    virtual SQLRETURN doExecute();
+    virtual SQLRETURN doFirst();
+    virtual SQLRETURN doInsert();
+    virtual SQLRETURN doLast();
+    virtual SQLRETURN doNext();
+    virtual SQLRETURN doPrepare( const QString &stringStatement );
+    virtual SQLRETURN doPrev();
+    virtual SQLRETURN doSeek( qlonglong nRow );
+    virtual SQLRETURN doSkip( qlonglong nRows );
+
+    virtual bool isValidRow();
+    virtual bool isValidRow( qulonglong nRow );
+
+protected:
+    MYSQL_STMT *pstm;
+    qulonglong  nRow; /* 1 -based (0 as BOS) */
+};
+
+#endif
+

Thread
Connector/ODBC 5 commit: r41 - in MYODBCRes: MYODBCResLib includepharvey16 Jan