LCOV - code coverage report
Current view: top level - src/odbc/unittests - convert_error.c (source / functions) Hit Total Coverage
Test: FreeTDS coverage Lines: 28 28 100.0 %
Date: 2025-02-21 09:36:06 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /*
       2             :  * test SQLBindParameter with text and Sybase 
       3             :  * test from Keith Woodard (bug #885122)
       4             :  */
       5             : #include "common.h"
       6             : 
       7             : static int test_num = 0;
       8             : 
       9             : static void
      10          48 : Test(const char *bind1, SQLSMALLINT type1, const char *bind2, SQLSMALLINT type2)
      11             : {
      12             :         char sql[512];
      13          48 :         char *val = "test";
      14          48 :         SQLLEN ind = 4;
      15          48 :         int id = 1;
      16          48 :         ODBC_BUF *odbc_buf = NULL;
      17             : 
      18          48 :         SQLFreeStmt(odbc_stmt, SQL_RESET_PARAMS);
      19             : 
      20          48 :         ++test_num;
      21          48 :         sprintf(sql, "insert into #test_output values (%s, %s)", bind1, bind2);
      22             : 
      23          48 :         CHKPrepare(T(sql), strlen(sql), "S");
      24          48 :         if (bind1[0] == '?')
      25          38 :                 CHKBindParameter(id++, SQL_PARAM_INPUT, SQL_C_LONG, type1, 3, 0, &test_num, 0, &ind, "S");
      26          48 :         if (bind2[0] == '?')
      27          38 :                 CHKBindParameter(id++, SQL_PARAM_INPUT, SQL_C_CHAR, type2, strlen(val) + 1, 0, (SQLCHAR *) val,
      28             :                                          0, &ind, "S");
      29          48 :         CHKExecute("S");
      30          48 :         ODBC_FREE();
      31          48 : }
      32             : 
      33             : int
      34          10 : main(void)
      35             : {
      36          10 :         odbc_use_version3 = 1;
      37          10 :         odbc_connect();
      38             : 
      39          10 :         odbc_command("create table #test_output (id int, msg text)");
      40             : 
      41          10 :         Test("?", SQL_INTEGER, "?", SQL_LONGVARCHAR);
      42          10 :         Test("123", SQL_INTEGER, "?", SQL_LONGVARCHAR);
      43          10 :         Test("?", SQL_INTEGER, "'foo'", SQL_LONGVARCHAR);
      44          10 :         Test("?", SQL_INTEGER, "?", SQL_VARCHAR);
      45             : 
      46             :         /*
      47             :          * Sybase cannot pass this test without complicated query parsing.
      48             :          * Query with blob columns cannot be prepared so prepared query must
      49             :          * be emulated loosing column information from server and Sybase do
      50             :          * not convert implicitly VARCHAR to INT
      51             :          */
      52          10 :         if (odbc_db_is_microsoft())
      53           8 :                 Test("?", SQL_VARCHAR, "?", SQL_LONGVARCHAR);
      54             :         else
      55           2 :                 ++test_num;
      56             : 
      57          10 :         odbc_disconnect();
      58             : 
      59             :         return 0;
      60             : }

Generated by: LCOV version 1.13