LCOV - code coverage report
Current view: top level - src/ctlib/unittests - t0003.c (source / functions) Hit Total Coverage
Test: FreeTDS coverage Lines: 36 65 55.4 %
Date: 2025-01-18 11:50:39 Functions: 1 1 100.0 %

          Line data    Source code
       1             : #include "common.h"
       2             : 
       3             : /* Testing: Retrieve CS_TEXT_TYPE using ct_bind() */
       4             : int
       5           8 : main(void)
       6             : {
       7             :         CS_CONTEXT *ctx;
       8             :         CS_CONNECTION *conn;
       9             :         CS_COMMAND *cmd;
      10           8 :         int i, verbose = 0;
      11             : 
      12             :         CS_RETCODE ret;
      13             :         CS_RETCODE results_ret;
      14             :         CS_INT result_type;
      15             :         CS_INT num_cols;
      16             : 
      17             :         CS_DATAFMT datafmt;
      18             :         CS_INT datalength;
      19             :         CS_SMALLINT ind;
      20           8 :         CS_INT count, row_count = 0;
      21             : 
      22             :         CS_CHAR name[1024];
      23             :         char large_sql[1024];
      24             :         char len600[601];
      25             :         char temp[11];
      26             : 
      27           8 :         len600[0] = 0;
      28           8 :         name[0] = 0;
      29         488 :         for (i = 0; i < 60; i++) {
      30         480 :                 sprintf(temp, "_abcde_%03d", (i + 1) * 10);
      31         480 :                 strcat(len600, temp);
      32             :         }
      33           8 :         len600[600] = '\0';
      34             : 
      35           8 :         printf("%s: Retrieve CS_TEXT_TYPE using ct_bind()\n", __FILE__);
      36             :         if (verbose) {
      37             :                 printf("Trying login\n");
      38             :         }
      39           8 :         check_call(try_ctlogin, (&ctx, &conn, &cmd, verbose));
      40             : 
      41           8 :         check_call(run_command, (cmd, "CREATE TABLE #test_table (id int, name text)"));
      42             : /*
      43             :         check_call(run_command, (cmd, "INSERT #test_table (id, name) VALUES (1, 'name1')"));
      44             : */
      45           8 :         sprintf(large_sql, "INSERT #test_table (id, name) VALUES (2, '%s')", len600);
      46           8 :         check_call(run_command, (cmd, large_sql));
      47             : 
      48           8 :         check_call(ct_command, (cmd, CS_LANG_CMD, "SELECT name FROM #test_table", CS_NULLTERM, CS_UNUSED));
      49           8 :         check_call(ct_send, (cmd));
      50           8 :         while ((results_ret = ct_results(cmd, &result_type)) == CS_SUCCEED) {
      51          16 :                 switch ((int) result_type) {
      52             :                 case CS_CMD_SUCCEED:
      53             :                         break;
      54             :                 case CS_CMD_DONE:
      55             :                         break;
      56           0 :                 case CS_CMD_FAIL:
      57           0 :                         fprintf(stderr, "ct_results() result_type CS_CMD_FAIL.\n");
      58           0 :                         return 1;
      59           8 :                 case CS_ROW_RESULT:
      60           8 :                         check_call(ct_res_info, (cmd, CS_NUMDATA, &num_cols, CS_UNUSED, NULL));
      61           8 :                         if (num_cols != 1) {
      62           0 :                                 fprintf(stderr, "num_cols %d != 1", num_cols);
      63           0 :                                 return 1;
      64             :                         }
      65           8 :                         check_call(ct_describe, (cmd, 1, &datafmt));
      66           8 :                         datafmt.format = CS_FMT_NULLTERM;
      67           8 :                         if (datafmt.maxlength > 1024) {
      68           8 :                                 datafmt.maxlength = 1024;
      69             :                         }
      70           8 :                         check_call(ct_bind, (cmd, 1, &datafmt, name, &datalength, &ind));
      71             : 
      72           8 :                         while (((ret = ct_fetch(cmd, CS_UNUSED, CS_UNUSED, CS_UNUSED, &count)) == CS_SUCCEED)
      73           8 :                                || (ret == CS_ROW_FAIL)) {
      74           8 :                                 row_count += count;
      75           8 :                                 if (ret == CS_ROW_FAIL) {
      76           0 :                                         fprintf(stderr, "ct_fetch() CS_ROW_FAIL on row %d.\n", row_count);
      77           0 :                                         return 1;
      78             :                                 } else {        /* ret == CS_SUCCEED */
      79             :                                         if (verbose) {
      80             :                                                 printf("name = '%s'\n", name);
      81             :                                         }
      82           8 :                                         if (strcmp(name, len600)) {
      83           0 :                                                 fprintf(stderr, "Bad return:\n'%s'\n! =\n'%s'\n", name, len600);
      84           0 :                                                 return 1;
      85             :                                         }
      86           8 :                                         if (datalength != strlen(name) + 1) {
      87           0 :                                                 fprintf(stderr, "Bad count:\n'%ld'\n! =\n'%d'\n", (long) strlen(name) + 1, count);
      88           0 :                                                 return 1;
      89             :                                         }
      90             :                                 }
      91             :                         }
      92           8 :                         switch ((int) ret) {
      93             :                         case CS_END_DATA:
      94             :                                 break;
      95           0 :                         case CS_FAIL:
      96           0 :                                 fprintf(stderr, "ct_fetch() returned CS_FAIL.\n");
      97           0 :                                 return 1;
      98           0 :                         default:
      99           0 :                                 fprintf(stderr, "ct_fetch() unexpected return.\n");
     100           0 :                                 return 1;
     101             :                         }
     102             :                         break;
     103           0 :                 case CS_COMPUTE_RESULT:
     104           0 :                         fprintf(stderr, "ct_results() unexpected CS_COMPUTE_RESULT.\n");
     105           0 :                         return 1;
     106           0 :                 default:
     107           0 :                         fprintf(stderr, "ct_results() unexpected result_type.\n");
     108           0 :                         return 1;
     109             :                 }
     110             :         }
     111           8 :         switch ((int) results_ret) {
     112             :         case CS_END_RESULTS:
     113             :                 break;
     114           0 :         case CS_FAIL:
     115           0 :                 fprintf(stderr, "ct_results() failed.\n");
     116           0 :                 return 1;
     117             :                 break;
     118           0 :         default:
     119           0 :                 fprintf(stderr, "ct_results() unexpected return.\n");
     120           0 :                 return 1;
     121             :         }
     122             : 
     123             :         if (verbose) {
     124             :                 printf("Trying logout\n");
     125             :         }
     126           8 :         check_call(try_ctlogout, (ctx, conn, cmd, verbose));
     127             : 
     128           8 :         return 0;
     129             : }

Generated by: LCOV version 1.13