OSDN Git Service

*** empty log message ***
authorMichael Meskes <meskes@postgresql.org>
Sun, 7 Mar 1999 08:01:18 +0000 (08:01 +0000)
committerMichael Meskes <meskes@postgresql.org>
Sun, 7 Mar 1999 08:01:18 +0000 (08:01 +0000)
src/interfaces/ecpg/ChangeLog
src/interfaces/ecpg/lib/ecpglib.c
src/interfaces/ecpg/preproc/Makefile
src/interfaces/ecpg/preproc/preproc.y
src/interfaces/ecpg/test/test1.pgc
src/interfaces/ecpg/test/test3.pgc [new file with mode: 0644]

index 9077bee..66ad701 100644 (file)
@@ -472,7 +472,7 @@ Mon Feb 22 19:47:45 CET 1999
 
        - Added 'at <db_connection>' option to all commands it is apllicable
          to. Due to changing the API of some libecpg functions this
-         requires me to increase the major version number.
+         requires me to increase the major version number of libecpg.
        - Synced pgc.l with scan.l.
        - Added support for unions.
 
@@ -498,5 +498,9 @@ Thu Mar  4 19:49:28 CET 1999
        - Switched memory allocation to calloc() to make sure memory is
          cleared.
        - Fixed varchar auto-allocating.
+
+Sat Mar  6 14:06:07 CET 1999
+
+       - Replaced placeholder ';;' by '?' since this is what standard says.
        - Set library version to 3.0.0
-       - Set ecpg version to 3.0.0
+       - Set ecpg version to 2.6.0
index e4e0391..8f60b0f 100644 (file)
@@ -129,7 +129,7 @@ register_error(long code, char *fmt,...)
 static struct connection *
 get_connection(const char *connection_name)
 {
-       struct connection *con = all_connections;;
+       struct connection *con = all_connections;
        
        if (connection_name == NULL || strcmp(connection_name, "CURRENT") == 0)
                return actual_connection;
@@ -377,11 +377,11 @@ next_insert(char *text)
        char *ptr = text;
        bool string = false;
        
-       for (; ptr[1] != '\0' && (ptr[0] != ';' || ptr[1] != ';' || string); ptr++)
-               if (ptr[0] == '\'')
+       for (; *ptr != '\0' && (*ptr != '?' || string); ptr++)
+               if (*ptr == '\'')
                        string = string ? false : true;
                        
-       return (ptr[1] == '\0') ? NULL : ptr;
+       return (*ptr == '\0') ? NULL : ptr;
 }
 
 static bool
@@ -604,7 +604,7 @@ ECPGexecute(struct statement * stmt)
                        strcat(newcopy,
                                   copiedquery
                                   + (p - newcopy)
-                                  + sizeof(";;") - 1 /* don't count the '\0' */);
+                                  + sizeof("?") - 1 /* don't count the '\0' */);
                }
 
                /*
@@ -675,7 +675,7 @@ ECPGexecute(struct statement * stmt)
                                {
                                        ECPGlog("ECPGexecute line %d: Incorrect number of matches: %d\n",
                                                        stmt->lineno, ntuples);
-                                       register_error(ECPG_NOT_FOUND, "Data not found line %d.", stmt->lineno);
+                                       register_error(ECPG_NOT_FOUND, "No data found line %d.", stmt->lineno);
                                        status = false;
                                        break;
                                }
@@ -1266,8 +1266,8 @@ replace_variables(char *text)
                        
                if (!string && *ptr == ':')
                {
-                       ptr[0] = ptr[1] = ';';
-                       for (ptr += 2; *ptr && isvarchar(*ptr); ptr++)
+                       *ptr = '?';
+                       for (++ptr; *ptr && isvarchar(*ptr); ptr++)
                                *ptr = ' ';
                }
        }
@@ -1307,7 +1307,7 @@ ECPGprepare(int lineno, char *name, char *variable)
         stmt->command = ecpg_strdup(variable, lineno);
         stmt->inlist = stmt->outlist = NULL;
         
-        /* if we have C variables in our statment replace them with ';;' */
+        /* if we have C variables in our statment replace them with '?' */
         replace_variables(stmt->command);                      
         
        /* add prepared statement to our list */
index ecdadfe..e851820 100644 (file)
@@ -1,8 +1,8 @@
 SRCDIR= ../../..
 include $(SRCDIR)/Makefile.global
 
-MAJOR_VERSION=3
-MINOR_VERSION=0
+MAJOR_VERSION=2
+MINOR_VERSION=6
 PATCHLEVEL=0
 
 CFLAGS+=-I../include -DMAJOR_VERSION=$(MAJOR_VERSION) \
index b60cfdb..1f5bb30 100644 (file)
@@ -1097,7 +1097,7 @@ user_group_clause:  IN GROUP user_group_list      { $$ = cat2_str(make1_str("in group
                        | /*EMPTY*/             { $$ = make1_str(""); }
                ;
 
-user_valid_clause:  VALID UNTIL Sconst                 { $$ = cat2_str(make1_str("valid until"), $3);; }
+user_valid_clause:  VALID UNTIL Sconst                 { $$ = cat2_str(make1_str("valid until"), $3); }
                        | /*EMPTY*/                     { $$ = make1_str(""); }
                ;
 
@@ -2221,7 +2221,7 @@ set_opt:  SETOF                                   { $$ = make1_str("setof"); }
 
 RemoveStmt:  DROP remove_type name
                                {
-                                       $$ = cat3_str(make1_str("drop"), $2, $3);;
+                                       $$ = cat3_str(make1_str("drop"), $2, $3);
                                }
                ;
 
@@ -2931,7 +2931,7 @@ opt_select_limit:      LIMIT select_limit_value ',' select_offset_value
                | LIMIT select_limit_value OFFSET select_offset_value
                        { $$ = cat4_str(make1_str("limit"), $2, make1_str("offset"), $4); }
                | LIMIT select_limit_value
-                       { $$ = cat2_str(make1_str("limit"), $2);; }
+                       { $$ = cat2_str(make1_str("limit"), $2); }
                | OFFSET select_offset_value LIMIT select_limit_value
                        { $$ = cat4_str(make1_str("offset"), $2, make1_str("limit"), $4); }
                | OFFSET select_offset_value
@@ -3835,7 +3835,7 @@ a_expr:  attr opt_indirection
                | case_expr
                                {       $$ = $1; }
                | cinputvariable
-                               { $$ = make1_str(";;"); }
+                               { $$ = make1_str("?"); }
                ;
 
 /* Restricted expressions
@@ -3982,7 +3982,7 @@ extract_list:  extract_arg FROM a_expr
                | /* EMPTY */
                                {       $$ = make1_str(""); }
                | cinputvariable
-                               { $$ = make1_str(";;"); }
+                               { $$ = make1_str("?"); }
                ;
 
 extract_arg:  datetime         { $$ = $1; }
@@ -4734,7 +4734,7 @@ ECPGCursorStmt:  DECLARE name opt_cursor CURSOR FOR ident cursor_clause
                                        this->next = cur;
                                        this->name = $2;
                                        this->connection = connection;
-                                       this->command =  cat5_str(make1_str("declare"), mm_strdup($2), $3, make1_str("cursor for ;;"), $7);
+                                       this->command =  cat5_str(make1_str("declare"), mm_strdup($2), $3, make1_str("cursor for ?"), $7);
                                        this->argsresult = NULL;
 
                                        thisquery->type = &ecpg_query;
@@ -5037,7 +5037,7 @@ ECPGExecute : EXECUTE SQL_IMMEDIATE execstring
 
                add_variable(&argsinsert, thisquery, &no_indicator); 
 
-               $$ = make1_str(";;");
+               $$ = make1_str("?");
        }
        | EXECUTE ident 
        {
@@ -5052,7 +5052,7 @@ ECPGExecute : EXECUTE SQL_IMMEDIATE execstring
                add_variable(&argsinsert, thisquery, &no_indicator); 
        } opt_using
        {
-               $$ = make1_str(";;");
+               $$ = make1_str("?");
        }
 
 execstring: char_variable |
@@ -5860,7 +5860,7 @@ cinputvariable : cvariable indicator {
 
 civariableonly : cvariable {
                add_variable(&argsinsert, find_variable($1), &no_indicator); 
-               $$ = make1_str(";;");
+               $$ = make1_str("?");
 }
 
 cvariable: CVARIABLE                   { $$ = $1; }
index a1e13bb..503d879 100644 (file)
@@ -63,7 +63,7 @@ exec sql end declare section;
        printf("Inserted %d tuples via execute immediate\n", sqlca.sqlerrd[2]);
 
         strcpy(msg, "execute insert 4");
-        sprintf(command, "insert into test(name, amount, letter) select name, amount+;;, letter from test");
+        sprintf(command, "insert into test(name, amount, letter) select name, amount+?, letter from test");
        exec sql prepare I from :command;
         exec sql at pm execute I using :increment;
         
diff --git a/src/interfaces/ecpg/test/test3.pgc b/src/interfaces/ecpg/test/test3.pgc
new file mode 100644 (file)
index 0000000..fe6fb56
--- /dev/null
@@ -0,0 +1,240 @@
+#include <stdio.h>
+
+exec sql include header_test;
+
+exec sql type str is varchar[10];
+
+int
+main ()
+{
+       typedef struct { long born; short age; } birthinfo;
+       exec sql type birthinfo is struct { long born; short age; };
+exec sql begin declare section;
+       struct personal_struct  {       str name;
+                                       birthinfo birth;
+                               } personal;
+       struct personal_indicator {     int ind_name;
+                                       birthinfo ind_birth;
+                                 } ind_personal;
+       int *ind_married = NULL;
+       int children;
+       int ind_children;
+       str *married = NULL;
+       char *testname="Petra";
+       char *query="select name, born, age, married, children from meskes where name = :var1";
+exec sql end declare section;
+
+       exec sql declare cur cursor for
+              select name, born, age, married, children from meskes;
+
+       char msg[128], command[128];
+       FILE *dbgs;
+
+       if ((dbgs = fopen("log", "w")) != NULL)
+                ECPGdebug(1, dbgs);
+
+       strcpy(msg, "connect");
+       exec sql connect to unix:postgresql://localhost:5432/mm; 
+
+       strcpy(msg, "create");
+       exec sql create table meskes(name char(8), born integer, age smallint, married date, children integer);
+
+       strcpy(msg, "insert");
+       exec sql insert into meskes(name, married, children) values ('Petra', '19900404', 3);
+       exec sql insert into meskes(name, born, age, married, children) values ('Michael', 19660117, 33, '19900404', 3);
+       exec sql insert into meskes(name, born, age) values ('Carsten', 19910103, 8);
+       exec sql insert into meskes(name, born, age) values ('Marc', 19930907, 5);
+       exec sql insert into meskes(name, born, age) values ('Chris', 19970923, 1);
+
+       strcpy(msg, "commit");
+       exec sql commit;
+
+       strcpy(msg, "open");
+       exec sql open cur;
+
+       exec sql whenever not found do break;
+
+       while (1) {
+               strcpy(msg, "fetch");
+               exec sql fetch in cur into :personal:ind_personal, :married:ind_married, :children:ind_children;
+               printf("%8.8s", personal.name.arr);
+               if (ind_personal.ind_birth.born >= 0)
+                       printf(", born %d", personal.birth.born);
+               if (ind_personal.ind_birth.age >= 0)
+                       printf(", age = %d", personal.birth.age);
+               if (ind_married >= 0)
+                       printf(", married %10.10s", married->arr);
+               if (ind_children >= 0)
+                       printf(", children = %d", children);
+               putchar('\n');
+
+               free(married);
+               married = NULL;
+       }
+
+       strcpy(msg, "close");
+       exec sql close cur;
+
+       /* and now the same query with prepare */
+       exec sql prepare MM from :query;
+       exec sql declare prep cursor for MM;
+
+       strcpy(msg, "open");
+       exec sql open prep using :testname;
+
+       exec sql whenever not found do break;
+
+       while (1) {
+               strcpy(msg, "fetch");
+               exec sql fetch in prep into :personal:ind_personal, :married:ind_married, :children:ind_children;
+               printf("%8.8s", personal.name.arr);
+               if (ind_personal.ind_birth.born >= 0)
+                       printf(", born %d", personal.birth.born);
+               if (ind_personal.ind_birth.age >= 0)
+                       printf(", age = %d", personal.birth.age);
+               if (ind_married >= 0)
+                       printf(", married %10.10s", married->arr);
+               if (ind_children >= 0)
+                       printf(", children = %d", children);
+               putchar('\n');
+       }
+
+       free(married);
+
+       strcpy(msg, "close");
+       exec sql close prep;
+
+       strcpy(msg, "drop");
+       exec sql drop table meskes;
+
+       strcpy(msg, "commit");
+       exec sql commit;
+
+       strcpy(msg, "disconnect"); 
+
+       exec sql disconnect;
+       if (dbgs != NULL)
+                fclose(dbgs);
+
+       return (0);
+}
+#include <stdio.h>
+
+exec sql include header_test;
+
+exec sql type str is varchar[10];
+
+int
+main ()
+{
+       typedef struct { long born; short age; } birthinfo;
+       exec sql type birthinfo is struct { long born; short age; };
+exec sql begin declare section;
+       struct personal_struct  {       str name;
+                                       birthinfo birth;
+                               } personal;
+       struct personal_indicator {     int ind_name;
+                                       birthinfo ind_birth;
+                                 } ind_personal;
+       int *ind_married = NULL;
+       int children;
+       int ind_children;
+       str *married = NULL;
+       char *testname="Petra";
+       char *query="select name, born, age, married, children from meskes where name = :var1";
+exec sql end declare section;
+
+       exec sql declare cur cursor for
+              select name, born, age, married, children from meskes;
+
+       char msg[128], command[128];
+       FILE *dbgs;
+
+       if ((dbgs = fopen("log", "w")) != NULL)
+                ECPGdebug(1, dbgs);
+
+       strcpy(msg, "connect");
+       exec sql connect to unix:postgresql://localhost:5432/mm; 
+
+       strcpy(msg, "create");
+       exec sql create table meskes(name char(8), born integer, age smallint, married date, children integer);
+
+       strcpy(msg, "insert");
+       exec sql insert into meskes(name, married, children) values ('Petra', '19900404', 3);
+       exec sql insert into meskes(name, born, age, married, children) values ('Michael', 19660117, 33, '19900404', 3);
+       exec sql insert into meskes(name, born, age) values ('Carsten', 19910103, 8);
+       exec sql insert into meskes(name, born, age) values ('Marc', 19930907, 5);
+       exec sql insert into meskes(name, born, age) values ('Chris', 19970923, 1);
+
+       strcpy(msg, "commit");
+       exec sql commit;
+
+       strcpy(msg, "open");
+       exec sql open cur;
+
+       exec sql whenever not found do break;
+
+       while (1) {
+               strcpy(msg, "fetch");
+               exec sql fetch in cur into :personal:ind_personal, :married:ind_married, :children:ind_children;
+               printf("%8.8s", personal.name.arr);
+               if (ind_personal.ind_birth.born >= 0)
+                       printf(", born %d", personal.birth.born);
+               if (ind_personal.ind_birth.age >= 0)
+                       printf(", age = %d", personal.birth.age);
+               if (ind_married >= 0)
+                       printf(", married %10.10s", married->arr);
+               if (ind_children >= 0)
+                       printf(", children = %d", children);
+               putchar('\n');
+
+               free(married);
+               married = NULL;
+       }
+
+       strcpy(msg, "close");
+       exec sql close cur;
+
+       /* and now the same query with prepare */
+       exec sql prepare MM from :query;
+       exec sql declare prep cursor for MM;
+
+       strcpy(msg, "open");
+       exec sql open prep using :testname;
+
+       exec sql whenever not found do break;
+
+       while (1) {
+               strcpy(msg, "fetch");
+               exec sql fetch in prep into :personal:ind_personal, :married:ind_married, :children:ind_children;
+               printf("%8.8s", personal.name.arr);
+               if (ind_personal.ind_birth.born >= 0)
+                       printf(", born %d", personal.birth.born);
+               if (ind_personal.ind_birth.age >= 0)
+                       printf(", age = %d", personal.birth.age);
+               if (ind_married >= 0)
+                       printf(", married %10.10s", married->arr);
+               if (ind_children >= 0)
+                       printf(", children = %d", children);
+               putchar('\n');
+       }
+
+       free(married);
+
+       strcpy(msg, "close");
+       exec sql close prep;
+
+       strcpy(msg, "drop");
+       exec sql drop table meskes;
+
+       strcpy(msg, "commit");
+       exec sql commit;
+
+       strcpy(msg, "disconnect"); 
+
+       exec sql disconnect;
+       if (dbgs != NULL)
+                fclose(dbgs);
+
+       return (0);
+}