LTP GCOV extension - code coverage report
Current view: directory - dblib/unittests - t0023.c
Test: FreeTDS coverage
Date: 2008-11-21 Instrumented lines: 146
Code covered: 70.5 % Executed lines: 103

       1                 : /* 
       2                 :  * Purpose: Test retrieving compute rows
       3                 :  * Functions: dbaltbind dbaltcolid dbaltop dbalttype dbnumalts
       4                 :  */
       5                 : 
       6                 : #if HAVE_CONFIG_H
       7                 : #include <config.h>
       8                 : #endif /* HAVE_CONFIG_H */
       9                 : 
      10                 : #include <stdio.h>
      11                 : 
      12                 : #if HAVE_STDLIB_H
      13                 : #include <stdlib.h>
      14                 : #endif /* HAVE_STDLIB_H */
      15                 : 
      16                 : #if HAVE_STRING_H
      17                 : #include <string.h>
      18                 : #endif /* HAVE_STRING_H */
      19                 : 
      20                 : #include <assert.h>
      21                 : #include <sqlfront.h>
      22                 : #include <sqldb.h>
      23                 : 
      24                 : #include "common.h"
      25                 : 
      26                 : static char software_version[] = "$Id: t0023.c,v 1.10 2005/05/23 08:06:25 freddy77 Exp $";
      27                 : static void *no_unused_var_warn[] = { software_version, no_unused_var_warn };
      28                 : 
      29                 : 
      30                 : int failed = 0;
      31                 : 
      32                 : 
      33                 : int
      34                 : main(int argc, char *argv[])
      35               2 : {
      36                 :         LOGINREC *login;
      37                 :         DBPROCESS *dbproc;
      38                 :         char cmd[1024];
      39                 :         int i;
      40                 :         DBINT rowint;
      41                 :         DBCHAR rowchar[2];
      42                 :         DBCHAR rowdate[32];
      43                 : 
      44                 :         DBINT rowtype;
      45                 :         DBINT computeint;
      46                 :         DBCHAR computedate[32];
      47                 : 
      48               2 :         set_malloc_options();
      49               2 :         read_login_info(argc, argv);
      50                 : 
      51               2 :         fprintf(stdout, "Start\n");
      52               2 :         add_bread_crumb();
      53                 : 
      54                 :         /* Fortify_EnterScope(); */
      55               2 :         dbinit();
      56                 : 
      57               2 :         add_bread_crumb();
      58               2 :         dberrhandle(syb_err_handler);
      59               2 :         dbmsghandle(syb_msg_handler);
      60                 : 
      61               2 :         fprintf(stdout, "About to logon\n");
      62                 : 
      63               2 :         add_bread_crumb();
      64               2 :         login = dblogin();
      65               2 :         DBSETLPWD(login, PASSWORD);
      66               2 :         DBSETLUSER(login, USER);
      67               2 :         DBSETLAPP(login, "t0023");
      68                 : 
      69               2 :         fprintf(stdout, "About to open\n");
      70                 : 
      71               2 :         add_bread_crumb();
      72               2 :         dbproc = dbopen(login, SERVER);
      73               2 :         if (strlen(DATABASE))
      74               2 :                 dbuse(dbproc, DATABASE);
      75               2 :         add_bread_crumb();
      76               2 :         dbloginfree(login);
      77               2 :         add_bread_crumb();
      78                 : 
      79               2 :         fprintf(stdout, "creating table\n");
      80               2 :         dbcmd(dbproc, "create table #dblib0023 (col1 int not null,  col2 char(1) not null, col3 datetime not null)");
      81               2 :         dbsqlexec(dbproc);
      82               4 :         while (dbresults(dbproc) == SUCCEED) {
      83                 :                 /* nop */
      84                 :         }
      85                 : 
      86               2 :         fprintf(stdout, "insert\n");
      87                 : 
      88               2 :         strcpy(cmd, "insert into #dblib0023 values (1, 'A', 'Jan  1 2002 10:00:00AM')");
      89               2 :         fprintf(stdout, "%s\n", cmd);
      90               2 :         dbcmd(dbproc, cmd);
      91               2 :         dbsqlexec(dbproc);
      92               4 :         while (dbresults(dbproc) == SUCCEED) {
      93                 :                 /* nop */
      94                 :         }
      95               2 :         strcpy(cmd, "insert into #dblib0023 values (2, 'A', 'Jan  2 2002 10:00:00AM')");
      96               2 :         fprintf(stdout, "%s\n", cmd);
      97               2 :         dbcmd(dbproc, cmd);
      98               2 :         dbsqlexec(dbproc);
      99               4 :         while (dbresults(dbproc) == SUCCEED) {
     100                 :                 /* nop */
     101                 :         }
     102               2 :         strcpy(cmd, "insert into #dblib0023 values (3, 'A', 'Jan  3 2002 10:00:00AM')");
     103               2 :         fprintf(stdout, "%s\n", cmd);
     104               2 :         dbcmd(dbproc, cmd);
     105               2 :         dbsqlexec(dbproc);
     106               4 :         while (dbresults(dbproc) == SUCCEED) {
     107                 :                 /* nop */
     108                 :         }
     109               2 :         strcpy(cmd, "insert into #dblib0023 values (8, 'B', 'Jan  4 2002 10:00:00AM')");
     110               2 :         fprintf(stdout, "%s\n", cmd);
     111               2 :         dbcmd(dbproc, cmd);
     112               2 :         dbsqlexec(dbproc);
     113               4 :         while (dbresults(dbproc) == SUCCEED) {
     114                 :                 /* nop */
     115                 :         }
     116               2 :         strcpy(cmd, "insert into #dblib0023 values (9, 'B', 'Jan  5 2002 10:00:00AM')");
     117               2 :         fprintf(stdout, "%s\n", cmd);
     118               2 :         dbcmd(dbproc, cmd);
     119               2 :         dbsqlexec(dbproc);
     120               4 :         while (dbresults(dbproc) == SUCCEED) {
     121                 :                 /* nop */
     122                 :         }
     123                 : 
     124               2 :         fprintf(stdout, "select\n");
     125               2 :         strcpy(cmd, "select col1, col2, col3 from #dblib0023 order by col2 ");
     126               2 :         strcat(cmd, "compute sum(col1) by col2 ");
     127               2 :         strcat(cmd, "compute max(col3)");
     128               2 :         dbcmd(dbproc, cmd);
     129               2 :         dbsqlexec(dbproc);
     130               2 :         add_bread_crumb();
     131                 : 
     132                 : 
     133               2 :         if (dbresults(dbproc) != SUCCEED) {
     134               0 :                 add_bread_crumb();
     135               0 :                 failed = 1;
     136               0 :                 fprintf(stdout, "Was expecting a result set.\n");
     137               0 :                 exit(1);
     138                 :         }
     139               2 :         add_bread_crumb();
     140                 : 
     141                 : 
     142               8 :         for (i = 1; i <= dbnumcols(dbproc); i++) {
     143               6 :                 add_bread_crumb();
     144               6 :                 printf("col %d is %s\n", i, dbcolname(dbproc, i));
     145               6 :                 add_bread_crumb();
     146                 :         }
     147                 : 
     148               2 :         add_bread_crumb();
     149               2 :         fprintf(stdout, "binding row columns\n");
     150               2 :         if (SUCCEED != dbbind(dbproc, 1, INTBIND, -1, (BYTE *) & rowint)) {
     151               0 :                 failed = 1;
     152               0 :                 fprintf(stderr, "Had problem with bind col1\n");
     153               0 :                 abort();
     154                 :         }
     155               2 :         add_bread_crumb();
     156               2 :         if (SUCCEED != dbbind(dbproc, 2, STRINGBIND, -1, (BYTE *) rowchar)) {
     157               0 :                 failed = 1;
     158               0 :                 fprintf(stderr, "Had problem with bind col2\n");
     159               0 :                 abort();
     160                 :         }
     161               2 :         add_bread_crumb();
     162               2 :         if (SUCCEED != dbbind(dbproc, 3, STRINGBIND, -1, (BYTE *) rowdate)) {
     163               0 :                 failed = 1;
     164               0 :                 fprintf(stderr, "Had problem with bind col3\n");
     165               0 :                 abort();
     166                 :         }
     167                 : 
     168               2 :         add_bread_crumb();
     169                 : 
     170               2 :         fprintf(stdout, "testing compute clause 1\n");
     171                 : 
     172               2 :         if (dbnumalts(dbproc, 1) != 1) {
     173               0 :                 failed = 1;
     174               0 :                 fprintf(stderr, "Had problem with dbnumalts 1\n");
     175               0 :                 abort();
     176                 :         }
     177                 : 
     178               2 :         if (dbalttype(dbproc, 1, 1) != SYBINT4) {
     179               0 :                 failed = 1;
     180               0 :                 fprintf(stderr, "Had problem with dbalttype 1, 1\n");
     181               0 :                 abort();
     182                 :         }
     183                 : 
     184               2 :         if (dbaltcolid(dbproc, 1, 1) != 1) {
     185               0 :                 failed = 1;
     186               0 :                 fprintf(stderr, "Had problem with dbaltcolid 1, 1\n");
     187               0 :                 abort();
     188                 :         }
     189                 : 
     190               2 :         if (dbaltop(dbproc, 1, 1) != SYBAOPSUM) {
     191               0 :                 failed = 1;
     192               0 :                 fprintf(stderr, "Had problem with dbaltop 1, 1\n");
     193               0 :                 abort();
     194                 :         }
     195                 : 
     196               2 :         if (SUCCEED != dbaltbind(dbproc, 1, 1, INTBIND, -1, (BYTE *) & computeint)) {
     197               0 :                 failed = 1;
     198               0 :                 fprintf(stderr, "Had problem with dbaltbind 1, 1\n");
     199               0 :                 abort();
     200                 :         }
     201                 : 
     202                 : 
     203               2 :         add_bread_crumb();
     204                 : 
     205               2 :         fprintf(stdout, "testing compute clause 2\n");
     206                 : 
     207               2 :         if (dbnumalts(dbproc, 2) != 1) {
     208               0 :                 failed = 1;
     209               0 :                 fprintf(stderr, "Had problem with dbnumalts 2\n");
     210               0 :                 abort();
     211                 :         }
     212                 : 
     213               2 :         if (dbalttype(dbproc, 2, 1) != SYBDATETIME) {
     214               0 :                 failed = 1;
     215               0 :                 fprintf(stderr, "Had problem with dbalttype 2, 1\n");
     216               0 :                 abort();
     217                 :         }
     218                 : 
     219               2 :         if (dbaltcolid(dbproc, 2, 1) != 3) {
     220               0 :                 failed = 1;
     221               0 :                 fprintf(stderr, "Had problem with dbaltcolid 2, 1\n");
     222               0 :                 abort();
     223                 :         }
     224                 : 
     225               2 :         if (dbaltop(dbproc, 2, 1) != SYBAOPMAX) {
     226               0 :                 failed = 1;
     227               0 :                 fprintf(stderr, "Had problem with dbaltop 2, 1\n");
     228               0 :                 abort();
     229                 :         }
     230                 : 
     231               2 :         if (SUCCEED != dbaltbind(dbproc, 2, 1, STRINGBIND, -1, (BYTE *) computedate)) {
     232               0 :                 failed = 1;
     233               0 :                 fprintf(stderr, "Had problem with dbaltbind 2, 1\n");
     234               0 :                 abort();
     235                 :         }
     236                 : 
     237               2 :         add_bread_crumb();
     238                 : 
     239              20 :         while ((rowtype = dbnextrow(dbproc)) != NO_MORE_ROWS) {
     240                 : 
     241              16 :                 if (rowtype == REG_ROW) {
     242              10 :                         printf("gotten a regular row\n");
     243                 :                 }
     244                 : 
     245              16 :                 if (rowtype == 1) {
     246               4 :                         printf("gotten a compute row for clause 1\n");
     247               4 :                         printf("value of sum(col1) = %d\n", computeint);
     248                 :                 }
     249                 : 
     250              16 :                 if (rowtype == 2) {
     251               2 :                         printf("gotten a compute row for clause 2\n");
     252               2 :                         printf("value of max(col3) = %s\n", computedate);
     253                 : 
     254                 :                 }
     255                 :         }
     256                 : 
     257               2 :         add_bread_crumb();
     258               2 :         dbexit();
     259               2 :         add_bread_crumb();
     260                 : 
     261               2 :         fprintf(stdout, "dblib %s on %s\n", (failed ? "failed!" : "okay"), __FILE__);
     262               2 :         free_bread_crumb();
     263               2 :         return failed ? 1 : 0;
     264                 : }

Generated by: LTP GCOV extension version 1.6