LCOV - code coverage report
Current view: top level - src/odbc/unittests - cursor4.c (source / functions) Hit Total Coverage
Test: FreeTDS coverage Lines: 30 30 100.0 %
Date: 2024-03-23 08:24:27 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /* Test sp_cursorprepare / sp_cursorexecute usage to support SELECT FOR UPDATE
       2             :  * This test compiles and works fine with SQL Server Native Client, and uses
       3             :  * the sp_cursor* API Server Cursors ...
       4             :  */
       5             : 
       6             : #include "common.h"
       7             : 
       8             : static void
       9          18 : exec_direct(const char *stmt)
      10             : {
      11          18 :         SQLHSTMT odbc_stmt = SQL_NULL_HSTMT;
      12             : 
      13          18 :         CHKAllocHandle(SQL_HANDLE_STMT, (SQLHANDLE) odbc_conn, (SQLHANDLE *) & odbc_stmt, "S");
      14          18 :         odbc_command(stmt);
      15          18 :         CHKFreeHandle(SQL_HANDLE_STMT, (SQLHANDLE) odbc_stmt, "S");
      16          18 : }
      17             : 
      18             : int
      19           8 : main(void)
      20             : {
      21             :         char buff[64];
      22             :         SQLLEN ind;
      23             : 
      24           8 :         odbc_use_version3 = 1;
      25           8 :         odbc_connect();
      26             : 
      27           8 :         odbc_check_cursor();
      28             : 
      29           6 :         exec_direct("CREATE TABLE #t1 ( k INT, c VARCHAR(20))");
      30           6 :         exec_direct("INSERT INTO #t1 VALUES (1, 'aaa')");
      31             : 
      32           6 :         odbc_reset_statement();
      33             : 
      34           6 :         CHKSetStmtAttr(SQL_ATTR_CONCURRENCY, (SQLPOINTER) SQL_CONCUR_LOCK, SQL_IS_UINTEGER, "S");
      35             : 
      36           6 :         CHKSetCursorName(T("c112"), SQL_NTS, "S");
      37             : 
      38           6 :         CHKSetConnectAttr(SQL_ATTR_AUTOCOMMIT, TDS_INT2PTR(SQL_AUTOCOMMIT_OFF), 0, "S");
      39             : 
      40           6 :         CHKPrepare(T("SELECT * FROM #t1 FOR UPDATE"), SQL_NTS, "S");
      41             : 
      42           6 :         CHKExecute("S");
      43             : 
      44           6 :         CHKFetch("S");
      45             : 
      46           6 :         exec_direct("UPDATE #t1 SET c = 'xxx' WHERE CURRENT OF c112");
      47             : 
      48           6 :         CHKCloseCursor("SI");
      49             : 
      50           6 :         CHKEndTran(SQL_HANDLE_DBC, odbc_conn, SQL_COMMIT, "S");
      51             : 
      52           6 :         CHKSetConnectAttr(SQL_ATTR_AUTOCOMMIT, TDS_INT2PTR(SQL_AUTOCOMMIT_ON), 0, "S");
      53             : 
      54           6 :         CHKExecDirect(T("SELECT c FROM #t1 WHERE k = 1"), SQL_NTS, "S");
      55             : 
      56           6 :         CHKFetch("S");
      57             : 
      58           6 :         CHKGetData(1, SQL_C_CHAR, buff, sizeof(buff), &ind, "S");
      59             : 
      60           6 :         printf(">> New value after update = [%s] (should be [xxx]) \n", buff);
      61             : 
      62           6 :         CHKFreeHandle(SQL_HANDLE_STMT, (SQLHANDLE) odbc_stmt, "S");
      63           6 :         odbc_stmt = SQL_NULL_HSTMT;
      64             : 
      65           6 :         odbc_disconnect();
      66             : 
      67             :         return 0;
      68             : }

Generated by: LCOV version 1.13