LCOV - code coverage report
Current view: top level - src/odbc/unittests - rebindpar.c (source / functions) Hit Total Coverage
Test: FreeTDS coverage Lines: 40 40 100.0 %
Date: 2024-04-18 21:21:48 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 char software_version[] = "$Id: rebindpar.c,v 1.11 2011-07-12 10:16:59 freddy77 Exp $";
       6             : static void *no_unused_var_warn[] = { software_version, no_unused_var_warn };
       7             : 
       8             : #define SWAP_STMT(b) do { SQLHSTMT xyz = odbc_stmt; odbc_stmt = b; b = xyz; } while(0)
       9             : 
      10             : static HSTMT stmt;
      11             : 
      12             : static void
      13          60 : TestInsert(char *buf)
      14             : {
      15             :         SQLLEN ind;
      16          60 :         int l = strlen(buf);
      17             :         char sql[200];
      18             : 
      19             :         /* insert some data and test success */
      20          60 :         CHKBindParameter(1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR, l, 0, buf, l, &ind, "S");
      21             : 
      22          60 :         ind = l;
      23          60 :         CHKExecute("S");
      24             : 
      25          60 :         SWAP_STMT(stmt);
      26          60 :         sprintf(sql, "SELECT 1 FROM #tmp1 WHERE c = '%s'", buf);
      27          60 :         odbc_command(sql);
      28          60 :         CHKFetch("S");
      29          60 :         CHKFetch("No");
      30          60 :         CHKMoreResults("No");
      31          60 :         SWAP_STMT(stmt);
      32          60 : }
      33             : 
      34             : static void
      35          16 : Test(int prebind)
      36             : {
      37          16 :         ODBC_BUF *odbc_buf = NULL;
      38             :         SQLLEN ind;
      39             :         int i;
      40             :         char buf[100];
      41             : 
      42             :         /* build a string longer than 80 character (80 it's the default) */
      43          16 :         buf[0] = 0;
      44         352 :         for (i = 0; i < 21; ++i)
      45         336 :                 strcat(buf, "miao");
      46             : 
      47          16 :         odbc_command("DELETE FROM #tmp1");
      48             : 
      49          16 :         CHKAllocStmt(&stmt, "S");
      50             : 
      51          16 :         SWAP_STMT(stmt);
      52          16 :         if (prebind)
      53           8 :                 CHKBindParameter(1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR, 1, 0, buf, 1, &ind, "S");
      54             : 
      55          16 :         CHKPrepare(T("INSERT INTO #tmp1(c) VALUES(?)"), SQL_NTS, "S");
      56             : 
      57             :         /* try to insert an empty string, should not fail */
      58             :         /* NOTE this is currently the only test for insert a empty string using rpc */
      59          16 :         if (odbc_db_is_microsoft())
      60          12 :                 TestInsert("");
      61          16 :         TestInsert("a");
      62          16 :         TestInsert("bb");
      63          16 :         TestInsert(buf);
      64             : 
      65          16 :         CHKFreeStmt(SQL_DROP, "S");
      66             :         odbc_stmt = SQL_NULL_HSTMT;
      67          16 :         SWAP_STMT(stmt);
      68          16 :         ODBC_FREE();
      69          16 : }
      70             : 
      71             : int
      72           8 : main(int argc, char *argv[])
      73             : {
      74           8 :         odbc_connect();
      75             : 
      76           8 :         odbc_command("CREATE TABLE #tmp1 (c VARCHAR(200))");
      77             : 
      78           8 :         Test(1);
      79           8 :         Test(0);
      80             : 
      81           8 :         odbc_disconnect();
      82             : 
      83           8 :         printf("Done.\n");
      84             :         return 0;
      85             : }

Generated by: LCOV version 1.13