LCOV - code coverage report
Current view: top level - src/odbc/unittests - rebindpar.c (source / functions) Hit Total Coverage
Test: FreeTDS coverage Lines: 41 41 100.0 %
Date: 2025-01-18 11:50:39 Functions: 3 3 100.0 %

          Line data    Source code
       1             : #include "common.h"
       2             : 
       3             : /* Test for executing SQLExecute and rebinding parameters */
       4             : 
       5             : static HSTMT stmt;
       6             : 
       7             : static void
       8          60 : TestInsert(char *buf)
       9             : {
      10             :         SQLLEN ind;
      11          60 :         int l = strlen(buf);
      12             :         char sql[200];
      13             : 
      14             :         /* insert some data and test success */
      15          60 :         CHKBindParameter(1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR, l, 0, buf, l, &ind, "S");
      16             : 
      17          60 :         ind = l;
      18          60 :         CHKExecute("S");
      19             : 
      20          60 :         SWAP_STMT(stmt);
      21          60 :         sprintf(sql, "SELECT 1 FROM #tmp1 WHERE c = '%s'", buf);
      22          60 :         odbc_command(sql);
      23          60 :         CHKFetch("S");
      24          60 :         CHKFetch("No");
      25          60 :         CHKMoreResults("No");
      26          60 :         SWAP_STMT(stmt);
      27          60 : }
      28             : 
      29             : static void
      30          16 : Test(int prebind)
      31             : {
      32          16 :         ODBC_BUF *odbc_buf = NULL;
      33             :         SQLLEN ind;
      34             :         int i;
      35             :         char buf[100];
      36             : 
      37             :         /* build a string longer than 80 character (80 it's the default) */
      38          16 :         buf[0] = 0;
      39         352 :         for (i = 0; i < 21; ++i)
      40         336 :                 strcat(buf, "miao");
      41             : 
      42          16 :         odbc_command("DELETE FROM #tmp1");
      43             : 
      44          16 :         CHKAllocStmt(&stmt, "S");
      45             : 
      46          16 :         SWAP_STMT(stmt);
      47          16 :         if (prebind)
      48           8 :                 CHKBindParameter(1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR, 1, 0, buf, 1, &ind, "S");
      49             : 
      50          16 :         CHKPrepare(T("INSERT INTO #tmp1(c) VALUES(?)"), SQL_NTS, "S");
      51             : 
      52             :         /* try to insert an empty string, should not fail */
      53             :         /* NOTE this is currently the only test for insert a empty string using rpc */
      54          16 :         if (odbc_db_is_microsoft())
      55          12 :                 TestInsert("");
      56          16 :         TestInsert("a");
      57          16 :         TestInsert("bb");
      58          16 :         TestInsert(buf);
      59             : 
      60          16 :         CHKFreeStmt(SQL_DROP, "S");
      61          16 :         odbc_stmt = SQL_NULL_HSTMT;
      62          16 :         SWAP_STMT(stmt);
      63          16 :         ODBC_FREE();
      64          16 : }
      65             : 
      66             : int
      67           8 : main(void)
      68             : {
      69           8 :         odbc_connect();
      70             : 
      71           8 :         odbc_command("CREATE TABLE #tmp1 (c VARCHAR(200))");
      72             : 
      73           8 :         Test(1);
      74           8 :         Test(0);
      75             : 
      76           8 :         odbc_disconnect();
      77             : 
      78           8 :         printf("Done.\n");
      79             :         return 0;
      80             : }

Generated by: LCOV version 1.13