Thread

  1. ESQL-C INSERT Problem

    PostgreSQL Bugs List <pgsql-bugs@postgresql.org> — 2000-10-20T17:53:09Z

    Sascha Demetrio (sd@b-comp.de) reports a bug with a severity of 2
    The lower the number the more severe it is.
    
    Short Description
    ESQL-C INSERT Problem
    
    Long Description
    An embedded SQL/C program INSERT operation fails, if a string value
    submitted through a host variable ends with a backslash character.
    This bug is not triggered if the offending variable is the last
    variable in the INSERT statement.
    
    Running the test program (below) results in the following output:
    
    internal error: SQL error: Too many arguments in line 18.
    
    The program works if you remove the trailing backslash from `f1'.
    
    Version Info:
    OS: Linux / glibc-2.1.3
    PostgreSQL 7.0.2 on i586-pc-linux-gnu, compiled by gcc 2.95.2
    
    
    Sample Code
    Table:
    
    CREATE TABLE t1 ( f1 CHAR(10), f2 CHAR(10) );
    
    ESQL/C Code:
    
    --BEGIN-FILE--
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    EXEC SQL INCLUDE sqlca;
    
    int main(void)
    {
      EXEC SQL BEGIN DECLARE SECTION;
      char f1[11];
      char f2[11];
      EXEC SQL END DECLARE SECTION;
    
      EXEC SQL WHENEVER SQLERROR GOTO sql_error;
      EXEC SQL CONNECT TO testdb;
      strcpy(f1, "something\\");
      strcpy(f2, "FOO");
      EXEC SQL INSERT INTO t1 ( f1, f2 )
      VALUES ( :f1, :f2 );
      EXEC SQL COMMIT WORK;
      EXEC SQL DISCONNECT;
      return 0;
    sql_error:
      EXEC SQL WHENEVER SQLERROR STOP;
      fprintf(stderr, "internal error: SQL error: %s",
          sqlca.sqlerrm.sqlerrml
          ? sqlca.sqlerrm.sqlerrmc : "unknown error");
      EXEC SQL ROLLBACK;
      EXEC SQL DISCONNECT;
      return -1;
    }
    --END-FILE--
    
    
    No file was uploaded with this report