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

          Line data    Source code
       1             : #include "common.h"
       2             : 
       3             : int
       4           8 : main(void)
       5             : {
       6             :         SQLINTEGER id;
       7             :         SQLLEN ind1, ind2;
       8             :         char name[64];
       9             : 
      10           8 :         odbc_connect();
      11             : 
      12           8 :         odbc_command("CREATE TABLE #test(id INT, name VARCHAR(100))");
      13           8 :         odbc_command("INSERT INTO #test(id, name) VALUES(8, 'sysobjects')");
      14             : 
      15             :         /* bind before select */
      16           8 :         SQLBindCol(odbc_stmt, 1, SQL_C_SLONG, &id, sizeof(SQLINTEGER), &ind1);
      17           8 :         SQLBindCol(odbc_stmt, 2, SQL_C_CHAR, name, sizeof(name), &ind2);
      18             : 
      19             :         /* do select */
      20           8 :         odbc_command("SELECT id, name FROM #test WHERE name = 'sysobjects' SELECT 123, 'foo'");
      21             : 
      22             :         /* get results */
      23           8 :         id = -1;
      24           8 :         memset(name, 0, sizeof(name));
      25           8 :         CHKFetch("S");
      26             : 
      27           8 :         if (id == -1 || strcmp(name, "sysobjects") != 0) {
      28           0 :                 fprintf(stderr, "wrong results\n");
      29           0 :                 return 1;
      30             :         }
      31             : 
      32             :         /* discard others data */
      33           8 :         CHKFetch("No");
      34             : 
      35           8 :         SQLMoreResults(odbc_stmt);
      36             : 
      37           8 :         id = -1;
      38           8 :         memset(name, 0, sizeof(name));
      39           8 :         CHKFetch("S");
      40             : 
      41           8 :         if (id != 123 || strcmp(name, "foo") != 0) {
      42           0 :                 fprintf(stderr, "wrong results\n");
      43           0 :                 return 1;
      44             :         }
      45             : 
      46             :         /* discard others data */
      47           8 :         CHKFetch("No");
      48             : 
      49           8 :         SQLMoreResults(odbc_stmt);
      50             : 
      51             :         /* other select */
      52           8 :         odbc_command("SELECT 321, 'minni'");
      53             : 
      54             :         /* get results */
      55           8 :         id = -1;
      56           8 :         memset(name, 0, sizeof(name));
      57           8 :         CHKFetch("S");
      58             : 
      59           8 :         if (id != 321 || strcmp(name, "minni") != 0) {
      60           0 :                 fprintf(stderr, "wrong results\n");
      61           0 :                 return 1;
      62             :         }
      63             : 
      64             :         /* discard others data */
      65           8 :         CHKFetch("No");
      66             : 
      67           8 :         SQLMoreResults(odbc_stmt);
      68             : 
      69           8 :         odbc_disconnect();
      70             : 
      71           8 :         printf("Done.\n");
      72           8 :         return 0;
      73             : }

Generated by: LCOV version 1.13