LCOV - code coverage report
Current view: top level - src/ctlib/unittests - ct_cursor.c (source / functions) Hit Total Coverage
Test: FreeTDS coverage Lines: 188 365 51.5 %
Date: 2024-03-23 09:12:27 Functions: 2 2 100.0 %

          Line data    Source code
       1             : #include <config.h>
       2             : 
       3             : #include <stdio.h>
       4             : 
       5             : #ifdef HAVE_STRING_H
       6             : #include <string.h>
       7             : #endif
       8             : 
       9             : #include <ctpublic.h>
      10             : #include "common.h"
      11             : 
      12             : static int update_second_table(CS_COMMAND * cmd2, char *value);
      13             : 
      14             : int
      15           8 : main(int argc, char **argv)
      16             : {
      17             :         CS_CONTEXT *ctx;
      18             :         CS_CONNECTION *conn;
      19             :         CS_COMMAND *cmd;
      20             :         CS_COMMAND *cmd2;
      21             :         CS_RETCODE ret;
      22             :         CS_RETCODE results_ret;
      23             :         CS_INT result_type;
      24           8 :         CS_INT count, row_count = 0;
      25             :         CS_DATAFMT datafmt;
      26             :         CS_SMALLINT ind;
      27           8 :         int verbose = 1;
      28             :         CS_CHAR name[3]; 
      29             :         CS_CHAR col1[6];
      30             :         CS_INT datalength;
      31             :         CS_CHAR text[128];
      32             :         CS_INT num_cols, i, j;
      33             :         CS_INT props_value;
      34             : 
      35           8 :         printf("%s: Testing ct_cursor()\n", __FILE__);
      36             : 
      37             :         if (verbose) {
      38           8 :                 printf("Trying login\n");
      39             :         }
      40           8 :         ret = try_ctlogin(&ctx, &conn, &cmd, verbose);
      41           8 :         if (ret != CS_SUCCEED) {
      42           0 :                 fprintf(stderr, "Login failed\n");
      43           0 :                 return 1;
      44             :         }
      45             : 
      46           8 :         ret = ct_cmd_alloc(conn, &cmd2);
      47           8 :         if (ret != CS_SUCCEED) {
      48             :                 if (verbose) {
      49           0 :                         fprintf(stderr, "Command Alloc failed!\n");
      50             :                 }
      51           0 :                 return ret;
      52             :         }
      53             : 
      54           8 :         ret = run_command(cmd, "CREATE TABLE #test_table (col1 char(4))");
      55           8 :         if (ret != CS_SUCCEED)
      56             :                 return 1;
      57             : 
      58           8 :         ret = run_command(cmd, "INSERT #test_table (col1) VALUES ('AAA')");
      59           8 :         if (ret != CS_SUCCEED)
      60             :                 return 1;
      61           8 :         ret = run_command(cmd, "INSERT #test_table (col1) VALUES ('BBB')");
      62           8 :         if (ret != CS_SUCCEED)
      63             :                 return 1;
      64           8 :         ret = run_command(cmd, "INSERT #test_table (col1) VALUES ('CCC')");
      65           8 :         if (ret != CS_SUCCEED)
      66             :                 return 1;
      67             : 
      68           8 :         ret = run_command(cmd2, "CREATE TABLE #test_table2 (col1 char(4))");
      69           8 :         if (ret != CS_SUCCEED)
      70             :                 return 1;
      71             : 
      72           8 :         ret = run_command(cmd2, "INSERT #test_table2 (col1) VALUES ('---')");
      73           8 :         if (ret != CS_SUCCEED)
      74             :                 return 1;
      75             : 
      76             :         if (verbose) {
      77           8 :                 printf("Trying declare, rows , open in one SEND\n");
      78             :         }
      79             : 
      80           8 :         strcpy(text, "select col1 from #test_table where 1 = 1");
      81           8 :         strcpy(name, "c1");
      82             : 
      83           8 :         ret = ct_cursor(cmd, CS_CURSOR_DECLARE, name, CS_NULLTERM, text, CS_NULLTERM, CS_UNUSED);
      84             : 
      85           8 :         if (ret != CS_SUCCEED) {
      86           0 :                 fprintf(stderr, "ct_cursor declare failed\n");
      87           0 :                 return 1;
      88             :         }
      89             : 
      90           8 :         ret = ct_cursor(cmd, CS_CURSOR_ROWS, name, CS_NULLTERM, NULL, CS_UNUSED, (CS_INT) 1);
      91           8 :         if (ret != CS_SUCCEED) {
      92           0 :                 fprintf(stderr, "ct_cursor set cursor rows failed");
      93           0 :                 return 1;
      94             :         }
      95             : 
      96           8 :         ret = ct_cursor(cmd, CS_CURSOR_OPEN, name, CS_NULLTERM, text, CS_NULLTERM, CS_UNUSED);
      97             : 
      98           8 :         if (ret != CS_SUCCEED) {
      99           0 :                 fprintf(stderr, "ct_cursor open failed\n");
     100           0 :                 return 1;
     101             :         }
     102             : 
     103           8 :         ret = ct_send(cmd);
     104             : 
     105           8 :         if (ret != CS_SUCCEED) {
     106           0 :                 fprintf(stderr, "ct_send failed\n");
     107             :         }
     108             : 
     109          40 :         while ((results_ret = ct_results(cmd, &result_type)) == CS_SUCCEED) {
     110          32 :                 switch ((int) result_type) {
     111             : 
     112             :                 case CS_CMD_SUCCEED:
     113             :                 case CS_CMD_DONE:
     114             :                 case CS_CMD_FAIL:
     115             :                 case CS_STATUS_RESULT:
     116             :                         break;
     117             : 
     118           8 :                 case CS_CURSOR_RESULT:
     119             : 
     120           8 :                         ret = ct_cmd_props(cmd, CS_GET, CS_CUR_STATUS, &props_value, sizeof(CS_INT), NULL); 
     121           8 :                         if (ret != CS_SUCCEED) {
     122           0 :                                 fprintf(stderr, "ct_cmd_props() failed\n");
     123           0 :                                 return 1;
     124             :                         }
     125           8 :                         if (props_value & CS_CURSTAT_DECLARED) {
     126           0 :                                 fprintf(stderr, "ct_cmd_props claims cursor is in DECLARED state when it should be OPEN\n");
     127           0 :                                 return 1;
     128             :                         }
     129           8 :                         if (!(props_value & CS_CURSTAT_OPEN)) {
     130           0 :                                 fprintf(stderr, "ct_cmd_props claims cursor is not in OPEN state when it should be \n");
     131           0 :                                 return 1;
     132             :                         }
     133           8 :                         if (props_value & CS_CURSTAT_CLOSED) {
     134           0 :                                 fprintf(stderr, "ct_cmd_props claims cursor is in CLOSED state when it should be OPEN\n");
     135           0 :                                 return 1;
     136             :                         }
     137             : 
     138           8 :                         ret = ct_res_info(cmd, CS_NUMDATA, &num_cols, CS_UNUSED, NULL);
     139             : 
     140           8 :                         if (ret != CS_SUCCEED) {
     141           0 :                                 fprintf(stderr, "ct_res_info() failed");
     142           0 :                                 return 1;
     143             :                         }
     144             : 
     145           8 :                         if (num_cols != 1) {
     146           0 :                                 fprintf(stderr, "unexpected num of columns =  %d \n", num_cols);
     147           0 :                                 return 1;
     148             :                         }
     149             : 
     150          16 :                         for (i = 0; i < num_cols; i++) {
     151             : 
     152             :                                 /* here we can finally test for the return status column */
     153           8 :                                 ret = ct_describe(cmd, i + 1, &datafmt);
     154             : 
     155           8 :                                 if (ret != CS_SUCCEED) {
     156           0 :                                         fprintf(stderr, "ct_describe() failed for column %d\n", i);
     157           0 :                                         return 1;
     158             :                                 }
     159             : 
     160           8 :                                 if (datafmt.status & CS_RETURN) {
     161           0 :                                         printf("ct_describe() column %d \n", i);
     162             :                                 }
     163             : 
     164           8 :                                 datafmt.datatype = CS_CHAR_TYPE;
     165           8 :                                 datafmt.format = CS_FMT_NULLTERM;
     166           8 :                                 datafmt.maxlength = 6;
     167           8 :                                 datafmt.count = 1;
     168           8 :                                 datafmt.locale = NULL;
     169           8 :                                 ret = ct_bind(cmd, 1, &datafmt, col1, &datalength, &ind);
     170           8 :                                 if (ret != CS_SUCCEED) {
     171           0 :                                         fprintf(stderr, "ct_bind() failed\n");
     172           0 :                                         return 1;
     173             :                                 }
     174             : 
     175             :                         }
     176             :                         row_count = 0;
     177          32 :                         while (((ret = ct_fetch(cmd, CS_UNUSED, CS_UNUSED, CS_UNUSED, &count)) == CS_SUCCEED)
     178           8 :                                || (ret == CS_ROW_FAIL)) {
     179             : 
     180          24 :                                 if (row_count == 0) {
     181           8 :                                         for (j = 0; j < num_cols; j++) {
     182           8 :                                                 printf("\n%s\n", datafmt.name);
     183             :                                         }
     184           8 :                                         printf("------\n\n");
     185             :                                 }
     186             : 
     187          24 :                                 for (j = 0; j < num_cols; j++) {
     188          24 :                                         printf("%s\n\n", col1);
     189          24 :                                         row_count++;
     190             :                                 }
     191             : 
     192          24 :                                 ret = update_second_table(cmd2, col1);
     193          24 :                                 if (ret)
     194             :                                         return ret;
     195             :                         }
     196             : 
     197           8 :                         switch ((int) ret) {
     198             :                         case CS_END_DATA:
     199             :                                 break;
     200           0 :                         case CS_ROW_FAIL:
     201           0 :                                 fprintf(stderr, "ct_fetch() CS_ROW_FAIL on row %d.\n", row_count);
     202           0 :                                 return 1;
     203           0 :                         case CS_FAIL:
     204           0 :                                 fprintf(stderr, "ct_fetch() returned CS_FAIL.\n");
     205           0 :                                 return 1;
     206           0 :                         default:
     207           0 :                                 fprintf(stderr, "ct_fetch() unexpected return. %d\n", ret);
     208           0 :                                 return 1;
     209             :                         }
     210             :                         break;
     211             : 
     212           0 :                 case CS_COMPUTE_RESULT:
     213           0 :                         fprintf(stderr, "ct_results() unexpected CS_COMPUTE_RESULT.\n");
     214           0 :                         return 1;
     215           0 :                 default:
     216           0 :                         fprintf(stderr, "ct_results() unexpected result_type.\n");
     217           0 :                         return 1;
     218             :                 }
     219             :         }
     220             : 
     221             : 
     222           8 :         ret = ct_cursor(cmd, CS_CURSOR_CLOSE, name, CS_NULLTERM, NULL, CS_UNUSED, CS_DEALLOC);
     223             : 
     224           8 :         if (ret != CS_SUCCEED) {
     225           0 :                 fprintf(stderr, "ct_cursor(close) failed\n");
     226           0 :                 return ret;
     227             :         }
     228             : 
     229           8 :         if ((ret = ct_send(cmd)) != CS_SUCCEED) {
     230           0 :                 fprintf(stderr, "BILL ct_send() failed\n");
     231           0 :                 return ret;
     232             :         }
     233             : 
     234          12 :         while ((results_ret = ct_results(cmd, &result_type)) == CS_SUCCEED) {
     235           4 :                 if (result_type == CS_CMD_FAIL) {
     236           0 :                         fprintf(stderr, "ct_results(2) result_type CS_CMD_FAIL.\n");
     237           0 :                         return 1;
     238             :                 }
     239             :         }
     240           8 :         if (results_ret != CS_END_RESULTS) {
     241           0 :                 fprintf(stderr, "ct_results() returned BAD.\n");
     242           0 :                 return 1;
     243             :         }
     244             : 
     245           8 :         ret = ct_cmd_props(cmd, CS_GET, CS_CUR_STATUS, &props_value, sizeof(CS_INT), NULL); 
     246           8 :         if (ret != CS_SUCCEED) {
     247           0 :                 fprintf(stderr, "ct_cmd_props() failed");
     248           0 :                 return 1;
     249             :         }
     250             : 
     251           8 :         if (props_value != CS_CURSTAT_NONE) {
     252           0 :                 fprintf(stderr, "ct_cmd_props() CS_CUR_STATUS != CS_CURSTAT_NONE \n");
     253           0 :                 return 1;
     254             :         }
     255             : 
     256             :         if (verbose) {
     257           8 :                 printf("Trying declare, rows, open one at a time \n");
     258             :         }
     259             : 
     260           8 :         strcpy(text, "select col1 from #test_table where 2 = 2");
     261             : 
     262           8 :         ret = ct_cursor(cmd, CS_CURSOR_DECLARE, name, 3, text, CS_NULLTERM, CS_UNUSED);
     263             : 
     264           8 :         if (ret != CS_SUCCEED) {
     265           0 :                 fprintf(stderr, "ct_cursor declare failed\n");
     266           0 :                 return 1;
     267             :         }
     268             : 
     269           8 :         ret = ct_send(cmd);
     270             : 
     271           8 :         if (ret != CS_SUCCEED) {
     272           0 :                 fprintf(stderr, "ct_send failed\n");
     273             :         }
     274             : 
     275          12 :         while ((results_ret = ct_results(cmd, &result_type)) == CS_SUCCEED) {
     276           4 :                 if (result_type == CS_CMD_FAIL) {
     277           0 :                         fprintf(stderr, "ct_results(4) result_type CS_CMD_FAIL.\n");
     278           0 :                         return 1;
     279             :                 }
     280             :         }
     281           8 :         if (results_ret != CS_END_RESULTS) {
     282           0 :                 fprintf(stderr, "ct_results() returned BAD.\n");
     283           0 :                 return 1;
     284             :         }
     285             : 
     286           8 :         ret = ct_cursor(cmd, CS_CURSOR_ROWS, name, 3, NULL, CS_UNUSED, (CS_INT) 1);
     287           8 :         if (ret != CS_SUCCEED) {
     288           0 :                 fprintf(stderr, "ct_cursor set cursor rows failed");
     289           0 :                 return 1;
     290             :         }
     291             : 
     292           8 :         ret = ct_send(cmd);
     293             : 
     294           8 :         if (ret != CS_SUCCEED) {
     295           0 :                 fprintf(stderr, "ct_send failed\n");
     296             :         }
     297             : 
     298          12 :         while ((results_ret = ct_results(cmd, &result_type)) == CS_SUCCEED) {
     299           4 :                 if (result_type == CS_CMD_FAIL) {
     300           0 :                         fprintf(stderr, "ct_results(5) result_type CS_CMD_FAIL.\n");
     301           0 :                         return 1;
     302             :                 }
     303             :         }
     304           8 :         if (results_ret != CS_END_RESULTS) {
     305           0 :                 fprintf(stderr, "ct_results() returned BAD.\n");
     306           0 :                 return 1;
     307             :         }
     308             : 
     309           8 :         ret = ct_cursor(cmd, CS_CURSOR_OPEN, name, 3, text, 26, CS_UNUSED);
     310             : 
     311           8 :         if (ret != CS_SUCCEED) {
     312           0 :                 fprintf(stderr, "ct_cursor open failed\n");
     313           0 :                 return 1;
     314             :         }
     315             : 
     316           8 :         ret = ct_send(cmd);
     317             : 
     318           8 :         if (ret != CS_SUCCEED) {
     319           0 :                 fprintf(stderr, "ct_send failed\n");
     320             :         }
     321             : 
     322          32 :         while ((results_ret = ct_results(cmd, &result_type)) == CS_SUCCEED) {
     323          24 :                 switch ((int) result_type) {
     324             : 
     325             :                 case CS_CMD_SUCCEED:
     326             :                         break;
     327             :                 case CS_CMD_DONE:
     328             :                         break;
     329           0 :                 case CS_CMD_FAIL:
     330           0 :                         fprintf(stderr, "ct_results(6) result_type CS_CMD_FAIL.\n");
     331           0 :                         break;
     332           0 :                 case CS_STATUS_RESULT:
     333           0 :                         printf("ct_results: CS_STATUS_RESULT detected for sp_who\n");
     334             : 
     335           8 :                 case CS_CURSOR_RESULT:
     336           8 :                         ret = ct_res_info(cmd, CS_NUMDATA, &num_cols, CS_UNUSED, NULL);
     337             : 
     338           8 :                         if (ret != CS_SUCCEED) {
     339           0 :                                 fprintf(stderr, "ct_res_info() failed");
     340           0 :                                 return 1;
     341             :                         }
     342             : 
     343           8 :                         if (num_cols != 1) {
     344           0 :                                 fprintf(stderr, "unexpected num of columns =  %d \n", num_cols);
     345           0 :                                 return 1;
     346             :                         }
     347             : 
     348          16 :                         for (i = 0; i < num_cols; i++) {
     349             : 
     350             :                                 /* here we can finally test for the return status column */
     351           8 :                                 ret = ct_describe(cmd, i + 1, &datafmt);
     352             : 
     353           8 :                                 if (ret != CS_SUCCEED) {
     354           0 :                                         fprintf(stderr, "ct_describe() failed for column %d\n", i);
     355           0 :                                         return 1;
     356             :                                 }
     357             : 
     358           8 :                                 if (datafmt.status & CS_RETURN) {
     359           0 :                                         printf("ct_describe() column %d \n", i);
     360             :                                 }
     361             : 
     362           8 :                                 datafmt.datatype = CS_CHAR_TYPE;
     363           8 :                                 datafmt.format = CS_FMT_NULLTERM;
     364           8 :                                 datafmt.maxlength = 6;
     365           8 :                                 datafmt.count = 1;
     366           8 :                                 datafmt.locale = NULL;
     367           8 :                                 ret = ct_bind(cmd, 1, &datafmt, col1, &datalength, &ind);
     368           8 :                                 if (ret != CS_SUCCEED) {
     369           0 :                                         fprintf(stderr, "ct_bind() failed\n");
     370           0 :                                         return 1;
     371             :                                 }
     372             :                         }
     373             :                         row_count = 0;
     374          32 :                         while (((ret = ct_fetch(cmd, CS_UNUSED, CS_UNUSED, CS_UNUSED, &count)) == CS_SUCCEED)
     375           8 :                                || (ret == CS_ROW_FAIL)) {
     376             : 
     377          24 :                                 if (row_count == 0) {
     378           8 :                                         for (j = 0; j < num_cols; j++) {
     379           8 :                                                 printf("\n%s\n", datafmt.name);
     380             :                                         }
     381           8 :                                         printf("------\n\n");
     382             :                                 }
     383             : 
     384          24 :                                 for (j = 0; j < num_cols; j++) {
     385          24 :                                         printf("%s\n\n", col1);
     386          24 :                                         row_count++;
     387             :                                 }
     388             :                         }
     389             : 
     390             : 
     391           8 :                         switch ((int) ret) {
     392             :                         case CS_END_DATA:
     393             :                                 break;
     394           0 :                         case CS_ROW_FAIL:
     395           0 :                                 fprintf(stderr, "ct_fetch() CS_ROW_FAIL on row %d.\n", row_count);
     396           0 :                                 return 1;
     397           0 :                         case CS_FAIL:
     398           0 :                                 fprintf(stderr, "ct_fetch() returned CS_FAIL.\n");
     399           0 :                                 return 1;
     400           0 :                         default:
     401           0 :                                 fprintf(stderr, "ct_fetch() unexpected return. %d\n", ret);
     402           0 :                                 return 1;
     403             :                         }
     404             :                         break;
     405             : 
     406           0 :                 case CS_COMPUTE_RESULT:
     407           0 :                         fprintf(stderr, "ct_results() unexpected CS_COMPUTE_RESULT.\n");
     408           0 :                         return 1;
     409           0 :                 default:
     410           0 :                         fprintf(stderr, "ct_results() unexpected result_type.\n");
     411           0 :                         return 1;
     412             :                 }
     413             :         }
     414             : 
     415             : 
     416           8 :         ret = ct_cursor(cmd, CS_CURSOR_CLOSE, name, 3, NULL, CS_UNUSED, CS_UNUSED);
     417             : 
     418           8 :         if (ret != CS_SUCCEED) {
     419           0 :                 fprintf(stderr, "ct_cursor(close) failed\n");
     420           0 :                 return ret;
     421             :         }
     422             : 
     423           8 :         if ((ret = ct_send(cmd)) != CS_SUCCEED) {
     424           0 :                 fprintf(stderr, "ct_send() failed\n");
     425           0 :                 return ret;
     426             :         }
     427             : 
     428          12 :         while ((results_ret = ct_results(cmd, &result_type)) == CS_SUCCEED) {
     429           4 :                 if (result_type == CS_CMD_FAIL) {
     430           0 :                         fprintf(stderr, "ct_results(7) result_type CS_CMD_FAIL.\n");
     431           0 :                         return 1;
     432             :                 }
     433             :         }
     434           8 :         if (results_ret != CS_END_RESULTS) {
     435           0 :                 fprintf(stderr, "ct_results() returned BAD.\n");
     436           0 :                 return 1;
     437             :         }
     438           8 :         ret = ct_cursor(cmd, CS_CURSOR_DEALLOC, name, 3, NULL, CS_UNUSED, CS_UNUSED);
     439             : 
     440           8 :         if (ret != CS_SUCCEED) {
     441           0 :                 fprintf(stderr, "ct_cursor(dealloc) failed\n");
     442           0 :                 return ret;
     443             :         }
     444             : 
     445           8 :         if ((ret = ct_send(cmd)) != CS_SUCCEED) {
     446           0 :                 fprintf(stderr, "ct_send() failed\n");
     447           0 :                 return ret;
     448             :         }
     449             : 
     450          12 :         while ((results_ret = ct_results(cmd, &result_type)) == CS_SUCCEED) {
     451           4 :                 if (result_type == CS_CMD_FAIL) {
     452           0 :                         fprintf(stderr, "ct_results(8) result_type CS_CMD_FAIL.\n");
     453           0 :                         return 1;
     454             :                 }
     455             :         }
     456           8 :         if (results_ret != CS_END_RESULTS) {
     457           0 :                 fprintf(stderr, "ct_results() returned BAD.\n");
     458           0 :                 return 1;
     459             :         }
     460             : 
     461             :         if (verbose) {
     462           8 :                 printf("Running normal select command after cursor operations\n");
     463             :         }
     464             : 
     465           8 :         ret = ct_command(cmd, CS_LANG_CMD, "select col1 from #test_table", CS_NULLTERM, CS_UNUSED);
     466           8 :         if (ret != CS_SUCCEED) {
     467           0 :                 fprintf(stderr, "ct_command() failed\n");
     468           0 :                 return 1;
     469             :         }
     470           8 :         ret = ct_send(cmd);
     471           8 :         if (ret != CS_SUCCEED) {
     472           0 :                 fprintf(stderr, "ct_send() failed\n");
     473           0 :                 return 1;
     474             :         }
     475          24 :         while ((results_ret = ct_results(cmd, &result_type)) == CS_SUCCEED) {
     476          16 :                 switch ((int) result_type) {
     477             :                 case CS_CMD_SUCCEED:
     478             :                         break;
     479             :                 case CS_CMD_DONE:
     480             :                         break;
     481           0 :                 case CS_CMD_FAIL:
     482           0 :                         fprintf(stderr, "ct_results() result_type CS_CMD_FAIL.\n");
     483           0 :                         return 1;
     484           8 :                 case CS_ROW_RESULT:
     485           8 :                         datafmt.datatype = CS_CHAR_TYPE;
     486           8 :                         datafmt.format = CS_FMT_NULLTERM;
     487           8 :                         datafmt.maxlength = 6;
     488           8 :                         datafmt.count = 1;
     489           8 :                         datafmt.locale = NULL;
     490           8 :                         ret = ct_bind(cmd, 1, &datafmt, col1, &datalength, &ind);
     491           8 :                         if (ret != CS_SUCCEED) {
     492           0 :                                 fprintf(stderr, "ct_bind() failed\n");
     493           0 :                                 return 1;
     494             :                         }
     495             : 
     496          32 :                         while (((ret = ct_fetch(cmd, CS_UNUSED, CS_UNUSED, CS_UNUSED, &count)) == CS_SUCCEED)
     497           8 :                                || (ret == CS_ROW_FAIL)) {
     498          24 :                                 row_count += count;
     499          24 :                                 if (ret == CS_ROW_FAIL) {
     500           0 :                                         fprintf(stderr, "ct_fetch() CS_ROW_FAIL on row %d.\n", row_count);
     501           0 :                                         return 1;
     502          24 :                                 } else if (ret == CS_SUCCEED) {
     503             :                                         ;
     504             :                                 } else {
     505             :                                         break;
     506             :                                 }
     507             :                         }
     508           8 :                         switch ((int) ret) {
     509             :                         case CS_END_DATA:
     510             :                                 break;
     511           0 :                         case CS_FAIL:
     512           0 :                                 fprintf(stderr, "ct_fetch() returned CS_FAIL.\n");
     513           0 :                                 return 1;
     514           0 :                         default:
     515           0 :                                 fprintf(stderr, "ct_fetch() unexpected return.%d\n", ret);
     516           0 :                                 return 1;
     517             :                         }
     518             :                         break;
     519           0 :                 case CS_COMPUTE_RESULT:
     520           0 :                         fprintf(stderr, "ct_results() unexpected CS_COMPUTE_RESULT.\n");
     521           0 :                         return 1;
     522           0 :                 default:
     523           0 :                         fprintf(stderr, "ct_results() unexpected result_type. %d\n", result_type);
     524           0 :                         return 1;
     525             :                 }
     526             :         }
     527           8 :         switch ((int) results_ret) {
     528             :         case CS_END_RESULTS:
     529             :                 break;
     530           0 :         case CS_FAIL:
     531           0 :                 fprintf(stderr, "ct_results() failed.\n");
     532           0 :                 return 1;
     533             :                 break;
     534           0 :         default:
     535           0 :                 fprintf(stderr, "ct_results() unexpected return.\n");
     536           0 :                 return 1;
     537             :         }
     538             :         if (verbose) {
     539           8 :                 printf("Trying logout\n");
     540             :         }
     541             : 
     542           8 :         ct_cmd_drop(cmd2);
     543             : 
     544           8 :         ret = try_ctlogout(ctx, conn, cmd, verbose);
     545           8 :         if (ret != CS_SUCCEED) {
     546           0 :                 fprintf(stderr, "Logout failed\n");
     547           0 :                 return 2;
     548             :         }
     549             : 
     550             :         if (verbose) {
     551           8 :                 printf("Test suceeded\n");
     552             :         }
     553           8 :         return 0;
     554             : }
     555             : 
     556             : static int
     557          24 : update_second_table(CS_COMMAND * cmd2, char *value)
     558             : {
     559             : 
     560             :         CS_RETCODE ret;
     561             :         CS_RETCODE results_ret;
     562             :         CS_INT result_type;
     563          24 :         CS_INT count, row_count = 0;
     564             :         CS_DATAFMT datafmt;
     565             :         CS_SMALLINT ind;
     566             :         CS_CHAR col1[6];
     567             :         CS_INT datalength;
     568             :         CS_CHAR text[128];
     569             : 
     570          24 :         sprintf(text, "update #test_table2 set col1 = '%s' ", value);
     571          24 :         ret = run_command(cmd2, text);
     572          24 :         if (ret != CS_SUCCEED)
     573             :                 return 1;
     574             : 
     575          24 :         ret = ct_command(cmd2, CS_LANG_CMD, "select col1 from #test_table2", CS_NULLTERM, CS_UNUSED);
     576          24 :         if (ret != CS_SUCCEED) {
     577           0 :                 fprintf(stderr, "ct_command() failed\n");
     578           0 :                 return 1;
     579             :         }
     580          24 :         ret = ct_send(cmd2);
     581          24 :         if (ret != CS_SUCCEED) {
     582           0 :                 fprintf(stderr, "ct_send() failed\n");
     583           0 :                 return 1;
     584             :         }
     585          72 :         while ((results_ret = ct_results(cmd2, &result_type)) == CS_SUCCEED) {
     586          48 :                 switch ((int) result_type) {
     587             :                 case CS_CMD_SUCCEED:
     588             :                         break;
     589             :                 case CS_CMD_DONE:
     590             :                         break;
     591           0 :                 case CS_CMD_FAIL:
     592           0 :                         fprintf(stderr, "ct_results() result_type CS_CMD_FAIL.\n");
     593           0 :                         return 1;
     594          24 :                 case CS_ROW_RESULT:
     595          24 :                         datafmt.datatype = CS_CHAR_TYPE;
     596          24 :                         datafmt.format = CS_FMT_NULLTERM;
     597          24 :                         datafmt.maxlength = 6;
     598          24 :                         datafmt.count = 1;
     599          24 :                         datafmt.locale = NULL;
     600          24 :                         ret = ct_bind(cmd2, 1, &datafmt, col1, &datalength, &ind);
     601          24 :                         if (ret != CS_SUCCEED) {
     602           0 :                                 fprintf(stderr, "ct_bind() failed\n");
     603           0 :                                 return 1;
     604             :                         }
     605             : 
     606          48 :                         while (((ret = ct_fetch(cmd2, CS_UNUSED, CS_UNUSED, CS_UNUSED, &count)) == CS_SUCCEED)
     607          24 :                                || (ret == CS_ROW_FAIL)) {
     608          24 :                                 row_count += count;
     609          24 :                                 if (ret == CS_ROW_FAIL) {
     610           0 :                                         fprintf(stderr, "ct_fetch() CS_ROW_FAIL on row %d.\n", row_count);
     611           0 :                                         return 1;
     612          24 :                                 } else if (ret == CS_SUCCEED) {
     613             :                                         ;
     614             :                                 } else {
     615             :                                         break;
     616             :                                 }
     617             :                         }
     618          24 :                         switch ((int) ret) {
     619             :                         case CS_END_DATA:
     620             :                                 break;
     621           0 :                         case CS_FAIL:
     622           0 :                                 fprintf(stderr, "ct_fetch() returned CS_FAIL.\n");
     623           0 :                                 return 1;
     624           0 :                         default:
     625           0 :                                 fprintf(stderr, "ct_fetch() unexpected return.%d\n", ret);
     626           0 :                                 return 1;
     627             :                         }
     628             :                         break;
     629           0 :                 case CS_COMPUTE_RESULT:
     630           0 :                         fprintf(stderr, "ct_results() unexpected CS_COMPUTE_RESULT.\n");
     631           0 :                         return 1;
     632           0 :                 default:
     633           0 :                         fprintf(stderr, "ct_results() unexpected result_type. %d\n", result_type);
     634           0 :                         return 1;
     635             :                 }
     636             :         }
     637          24 :         switch ((int) results_ret) {
     638             :         case CS_END_RESULTS:
     639             :                 break;
     640           0 :         case CS_FAIL:
     641           0 :                 fprintf(stderr, "ct_results() failed.\n");
     642           0 :                 return 1;
     643             :                 break;
     644           0 :         default:
     645           0 :                 fprintf(stderr, "ct_results() unexpected return.\n");
     646           0 :                 return 1;
     647             :         }
     648             :         return 0;
     649             : }
     650             : 

Generated by: LCOV version 1.13