• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            r2100

              C++博客 :: 首頁 :: 聯系 :: 聚合  :: 管理
              8 Posts :: 9 Stories :: 2 Comments :: 0 Trackbacks

            常用鏈接

            留言簿(3)

            我參與的團隊

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            SQLExecDirect函數源代碼
            static SQLRETURN
            ODBCExecDirect(ODBCStmt 
            *stmt, SQLCHAR *szSqlStr, SQLINTEGER nSqlStr)
            {
                
            char *query;
                MapiMsg ret;
                MapiHdl hdl;

                hdl 
            = stmt->hdl;

                
            if (stmt->State >= EXECUTED1 || (stmt->State == EXECUTED0 && mapi_more_results(hdl))) {
                    
            /* Invalid cursor state */
                    addStmtError(stmt, 
            "24000", NULL, 0);
                    
            return SQL_ERROR;
                }

                
            /* TODO: convert ODBC escape sequences ( {d 'value'} or {t 'value'} or
                   {ts 'value'} or {escape 'e-char'} or {oj outer-join} or
                   {fn scalar-function} etc. ) to MonetDB SQL syntax 
            */
                query 
            = ODBCTranslateSQL(szSqlStr, (size_t) nSqlStr, stmt->noScan);

                ODBCResetStmt(stmt);

            #ifdef ODBCDEBUG
                ODBCLOG(
            "SQLExecDirect: \"%s\"\n", query);
            #endif

                ret 
            = mapi_query_handle(hdl, query);
                free(query);
                
            switch (ret) {
                
            case MOK:
                    
            break;
                
            case MTIMEOUT:
                    
            /* Communication link failure */
                    addStmtError(stmt, 
            "08S01", mapi_error_str(stmt->Dbc->mid), 0);
                    
            return SQL_ERROR;
                
            default:
                    
            /* General error */
                    addStmtError(stmt, 
            "HY000", mapi_error_str(stmt->Dbc->mid), 0);
                    
            return SQL_ERROR;
                }

                
            /* now get the result data and store it to our internal data structure */

                
            return ODBCInitResult(stmt);
            }

            As mentioned earlier, it is more efficient to reuse statements than to drop them and allocate new ones. Before executing a new SQL statement on a statement, applications should be sure that the current statement settings are appropriate. These include statement attributes, parameter bindings, and result set bindings. Generally, parameters and result sets for the old SQL statement need to be unbound (by calling SQLFreeStmt with the SQL_RESET_PARAMS and SQL_UNBIND options) and rebound for the new SQL statement.

            When the application has finished using the statement, it calls SQLFreeHandle to free the statement. After freeing the statement, it is an application programming error to use the statement's handle in a call to an ODBC function; doing so has undefined but probably fatal consequences.

            When SQLFreeHandle is called, the driver releases the structure used to store information about the statement.

            SQLDisconnect automatically frees all statements on a connection.


                     
            /**********************************************
             * ODBCStmt.c
             *
             * Description:
             * This file contains the functions which operate on
             * ODBC statement structures/objects (see ODBCStmt.h).
             *
             * Author: Martin van Dinther
             * Date  : 30 aug 2002
             *
             *********************************************
            */

            #include 
            "ODBCGlobal.h"
            #include 
            "ODBCStmt.h"

            #define ODBC_STMT_MAGIC_NR  5461    /* for internal sanity check only */


            /*
             * Creates a new allocated ODBCStmt object and initializes it.
             *
             * Precondition: none
             * Postcondition: returns a new ODBCStmt object
             
            */
            ODBCStmt 
            *
            newODBCStmt(ODBCDbc 
            *dbc)
            {
                ODBCStmt 
            *stmt = (ODBCStmt *) malloc(sizeof(ODBCStmt));
                assert(stmt);

                assert(dbc);
                assert(dbc
            ->mid);

                
            if (stmt == NULL) {
                    
            /* Memory allocation error */
                    addDbcError(dbc, 
            "HY001", NULL, 0);
                    
            return NULL;
                }

                stmt
            ->Dbc = dbc;
                stmt
            ->Error = NULL;
                stmt
            ->RetrievedErrors = 0;

                stmt
            ->State = INITED;
                stmt
            ->hdl = mapi_new_handle(dbc->mid);
                
            if (stmt->hdl == NULL) {
                    
            /* Memory allocation error */
                    addDbcError(dbc, 
            "HY001", NULL, 0);
                    free(stmt);
                    
            return NULL;
                }
                assert(stmt
            ->hdl);

                stmt
            ->currentRow = 0;
                stmt
            ->startRow = 0;
                stmt
            ->rowSetSize = 0;
                stmt
            ->queryid = -1;
                stmt
            ->nparams = 0;
                stmt
            ->querytype = -1;
                stmt
            ->rowcount = 0;

                
            /* add this stmt to the administrative linked stmt list */
                stmt
            ->next = dbc->FirstStmt;
                dbc
            ->FirstStmt = stmt;

                stmt
            ->cursorType = SQL_CURSOR_FORWARD_ONLY;
                stmt
            ->cursorScrollable = SQL_NONSCROLLABLE;
                stmt
            ->retrieveData = SQL_RD_ON;
                stmt
            ->noScan = SQL_NOSCAN_OFF;

                stmt
            ->ApplRowDescr = newODBCDesc(dbc);
                stmt
            ->ApplParamDescr = newODBCDesc(dbc);
                stmt
            ->ImplRowDescr = newODBCDesc(dbc);
                stmt
            ->ImplParamDescr = newODBCDesc(dbc);
                stmt
            ->AutoApplRowDescr = stmt->ApplRowDescr;
                stmt
            ->AutoApplParamDescr = stmt->ApplParamDescr;

                
            if (stmt->ApplRowDescr == NULL || stmt->ApplParamDescr == NULL || stmt->ImplRowDescr == NULL || stmt->ImplParamDescr == NULL) {
                    destroyODBCStmt(stmt);
                    
            return NULL;
                }

                stmt
            ->ApplRowDescr->sql_desc_alloc_type = SQL_DESC_ALLOC_AUTO;
                stmt
            ->ApplParamDescr->sql_desc_alloc_type = SQL_DESC_ALLOC_AUTO;
                stmt
            ->ImplRowDescr->sql_desc_alloc_type = SQL_DESC_ALLOC_AUTO;
                stmt
            ->ImplParamDescr->sql_desc_alloc_type = SQL_DESC_ALLOC_AUTO;
                stmt
            ->ImplRowDescr->Stmt = stmt;
                stmt
            ->ImplParamDescr->Stmt = stmt;

                stmt
            ->Type = ODBC_STMT_MAGIC_NR;    /* set it valid */

                
            return stmt;
            }

            SQLFreeHandle
            ODBCFreeStmt_(ODBCStmt 
            *stmt)
            {
                
            /* check if statement is not active */
                
            if (stmt->State >= EXECUTED0) {
                    
            /* should be closed first */
                    
            if (SQLFreeStmt_(stmt, SQL_CLOSE) == SQL_ERROR)
                        
            return SQL_ERROR;
                }

                
            /* Ready to destroy the stmt handle */
                destroyODBCStmt(stmt);
                
            return SQL_SUCCESS;
            }


            SQLFreeStmt

            SQLFreeStmt_(ODBCStmt 
            *stmt, SQLUSMALLINT option)
            {
                
            switch (option) {
                
            case SQL_CLOSE:
                    
            /* Note: this option is also called from SQLCancel() and
                       SQLCloseCursor(), so be careful when changing the code 
            */
                    
            /* close cursor, discard result set, set to prepared */
                    setODBCDescRecCount(stmt
            ->ImplRowDescr, 0);
                    stmt
            ->currentRow = 0;
                    stmt
            ->startRow = 0;
                    stmt
            ->rowSetSize = 0;

                    
            if (stmt->State == EXECUTED0)
                        stmt
            ->State = stmt->queryid >= 0 ? PREPARED0 : INITED;
                    
            else if (stmt->State >= EXECUTED1)
                        stmt
            ->State = stmt->queryid >= 0 ? PREPARED1 : INITED;

                    
            /* Important: do not destroy the bind parameters and columns! */
                    
            return SQL_SUCCESS;
                
            case SQL_DROP:
                    
            return ODBCFreeStmt_(stmt);
                
            case SQL_UNBIND:
                    setODBCDescRecCount(stmt
            ->ApplRowDescr, 0);
                    
            return SQL_SUCCESS;
                
            case SQL_RESET_PARAMS:
                    setODBCDescRecCount(stmt
            ->ApplParamDescr, 0);
                    setODBCDescRecCount(stmt
            ->ImplParamDescr, 0);
                    mapi_clear_params(stmt
            ->hdl);
                    
            return SQL_SUCCESS;
                
            default:
                    
            /* Invalid attribute/option identifier */
                    addStmtError(stmt, 
            "HY092", NULL, 0);
                    
            return SQL_ERROR;
                }

                
            /* not reached */
            }

            SQLHSTMT的結構
            typedef 
            struct tODBCDRIVERSTMT {
                
            /* Stmt properties */
                
            int Type;        /* structure type, used for handle validy test */
                ODBCError 
            *Error;    /* pointer to an Error object or NULL */
                
            int RetrievedErrors;    /* # of errors already retrieved by SQLError */
                ODBCDbc 
            *Dbc;        /* Connection context */
                
            struct tODBCDRIVERSTMT *next;    /* the linked list of stmt's in this Dbc */
                
            enum StatementState State;    /* needed to detect invalid cursor state */
                MapiHdl hdl;

                unsigned 
            int rowcount;    /* # affected rows */

                
            /* startRow is the row number of first row in the result
                   set (0 based); rowSetSize is the number of rows in the
                   current result set; currentRow is the row number of the
                   current row within the current result set 
            */
                unsigned 
            int currentRow;
                unsigned 
            int startRow;
                unsigned 
            int rowSetSize;

                unsigned 
            int currentCol; /* used by SQLGetData() */
                SQLINTEGER retrieved;    
            /* amount of data retrieved */
                
            int queryid;        /* the query to be executed */
                
            int nparams;        /* the number of parameters expected */

                
            int querytype;        /* query type as returned by server */

                SQLUINTEGER cursorType;
                SQLUINTEGER cursorScrollable;
                SQLUINTEGER retrieveData;
                SQLUINTEGER noScan;

                ODBCDesc 
            *ApplRowDescr;    /* Application Row Descriptor (ARD) */
                ODBCDesc 
            *ApplParamDescr; /* Application Parameter Descriptor (APD) */
                ODBCDesc 
            *ImplRowDescr;    /* Implementation Row Descriptor (IRD) */
                ODBCDesc 
            *ImplParamDescr; /* Implementation Parameter Descriptor (IPD) */

                ODBCDesc 
            *AutoApplRowDescr; /* Auto-allocated ARD */
                ODBCDesc 
            *AutoApplParamDescr; /* Auto-allocated APD */

                
            /* Stmt children: none yet */
            } ODBCStmt;






            posted on 2008-09-11 11:31 r2100 閱讀(1142) 評論(2)  編輯 收藏 引用

            Feedback

            # re: http://msdn.microsoft.com/en-us/library/ms716303(VS.85).aspx 2008-09-11 11:32 r2100
            但是一直沒有找到實例,郁悶  回復  更多評論
              

            # re: http://msdn.microsoft.com/en-us/library/ms716303(VS.85).aspx 2009-01-28 18:01 張三
            安裝不成。。。  回復  更多評論
              

            99久久精品日本一区二区免费| 国内精品久久久久影院免费| 国产亚洲成人久久| 大伊人青草狠狠久久| 久久丫精品国产亚洲av不卡| 久久久久亚洲AV无码观看| 久久久久波多野结衣高潮| 久久人人爽人人爽人人av东京热 | 麻豆AV一区二区三区久久| 久久久久亚洲AV无码专区首JN | 免费精品久久久久久中文字幕| 久久国产三级无码一区二区| 久久久久久A亚洲欧洲AV冫| 中文字幕久久亚洲一区| 欧洲精品久久久av无码电影| 人妻精品久久无码区| 丰满少妇人妻久久久久久4| 久久免费99精品国产自在现线 | 2021国产成人精品久久| 久久97久久97精品免视看| 日本国产精品久久| 欧美黑人又粗又大久久久| 狠狠色丁香婷综合久久| 久久99热这里只有精品国产 | 亚洲国产欧洲综合997久久| 91久久婷婷国产综合精品青草| 久久―日本道色综合久久| 久久精品国产亚洲av瑜伽| 亚洲国产日韩欧美久久| 久久99国产综合精品免费| 99久久国产综合精品五月天喷水| 日本久久久久久久久久| 无码人妻精品一区二区三区久久久| 久久午夜羞羞影院免费观看| 精品999久久久久久中文字幕 | 91亚洲国产成人久久精品| 久久乐国产综合亚洲精品| 久久久久亚洲av成人网人人软件| 人妻无码αv中文字幕久久琪琪布| 久久e热在这里只有国产中文精品99| 久久天天躁狠狠躁夜夜不卡|