LCOV - code coverage report
Current view: top level - src/odbc/unittests - cursor4.c (source / functions) Hit Total Coverage
Test: FreeTDS coverage Lines: 31 31 100.0 %
Date: 2025-04-24 11:49:38 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          24 : exec_direct(const char *stmt)
      10             : {
      11          24 :         SQLHSTMT odbc_stmt = SQL_NULL_HSTMT;
      12             : 
      13          24 :         CHKAllocHandle(SQL_HANDLE_STMT, (SQLHANDLE) odbc_conn, (SQLHANDLE *) & odbc_stmt, "S");
      14          24 :         odbc_command(stmt);
      15          24 :         CHKFreeHandle(SQL_HANDLE_STMT, (SQLHANDLE) odbc_stmt, "S");
      16          24 : }
      17             : 
      18          10 : TEST_MAIN()
      19             : {
      20             :         char buff[64];
      21             :         SQLLEN ind;
      22             : 
      23          10 :         odbc_use_version3 = 1;
      24          10 :         odbc_connect();
      25             : 
      26          10 :         odbc_check_cursor();
      27             : 
      28           8 :         exec_direct("CREATE TABLE #t1 ( k INT, c VARCHAR(20))");
      29           8 :         exec_direct("INSERT INTO #t1 VALUES (1, 'aaa')");
      30             : 
      31           8 :         odbc_reset_statement();
      32             : 
      33           8 :         CHKSetStmtAttr(SQL_ATTR_CONCURRENCY, (SQLPOINTER) SQL_CONCUR_LOCK, SQL_IS_UINTEGER, "S");
      34             : 
      35           8 :         CHKSetCursorName(T("c112"), SQL_NTS, "S");
      36             : 
      37           8 :         CHKSetConnectAttr(SQL_ATTR_AUTOCOMMIT, TDS_INT2PTR(SQL_AUTOCOMMIT_OFF), 0, "S");
      38             : 
      39           8 :         CHKPrepare(T("SELECT * FROM #t1 FOR UPDATE"), SQL_NTS, "S");
      40             : 
      41           8 :         CHKExecute("S");
      42             : 
      43           8 :         CHKFetch("S");
      44             : 
      45           8 :         exec_direct("UPDATE #t1 SET c = 'xxx' WHERE CURRENT OF c112");
      46             : 
      47           8 :         CHKCloseCursor("SI");
      48             : 
      49           8 :         CHKEndTran(SQL_HANDLE_DBC, odbc_conn, SQL_COMMIT, "S");
      50             : 
      51           8 :         CHKSetConnectAttr(SQL_ATTR_AUTOCOMMIT, TDS_INT2PTR(SQL_AUTOCOMMIT_ON), 0, "S");
      52             : 
      53           8 :         CHKExecDirect(T("SELECT c FROM #t1 WHERE k = 1"), SQL_NTS, "S");
      54             : 
      55           8 :         CHKFetch("S");
      56             : 
      57           8 :         CHKGetData(1, SQL_C_CHAR, buff, sizeof(buff), &ind, "S");
      58             : 
      59           8 :         printf(">> New value after update = [%s] (should be [xxx]) \n", buff);
      60             : 
      61           8 :         CHKFreeHandle(SQL_HANDLE_STMT, (SQLHANDLE) odbc_stmt, "S");
      62           8 :         odbc_stmt = SQL_NULL_HSTMT;
      63             : 
      64           8 :         odbc_disconnect();
      65             : 
      66           8 :         return 0;
      67             : }

Generated by: LCOV version 1.13