Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.os.vms    |    DEC's VAX* line of computers & VMS.    |    264,096 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 262,781 of 264,096    |
|    =?UTF-8?Q?Arne_Vajh=C3=B8j?= to Lawrence D'Oliveiro    |
|    Re: VMS x86-64 database server    |
|    07 Jul 25 14:07:31    |
   
   From: arne@vajhoej.dk   
      
   On 7/6/2025 10:42 PM, Lawrence D'Oliveiro wrote:   
   > On Sun, 6 Jul 2025 19:58:04 -0400, Arne Vajhøj wrote:   
   >> But in embedded SQL then it is the standard way to do queries.   
   >   
   > Not sure what “embedded SQL” means. I normally use SQL “embedded” in   
   an   
   > app written in some other programming language.   
      
   Embedded SQL is a thing or was a thing 30-40-50 years ago.   
      
   Basically you write source code with SQL statements prefixed   
   by EXEC SQL, put it through a pre-compiler to get valid   
   code in whatever language (Cobol, PL/I, C or whatever).   
      
   Here is C call API code:   
      
    PGresult *res;   
    res = PQprepare(con, "stmt_selectf1f2fromt1", "SELECT f1,f2 FROM   
   t1", 0, NULL);   
    PQclear(res);   
    res = PQexecPrepared(con, "stmt_selectf1f2fromt1", 0, NULL, NULL,   
   NULL, 0);   
    int nrows = PQntuples(res);   
    for(int i = 0; i < nrows; i++)   
    {   
    int f1 = atoi(PQgetvalue(res, i, 0));   
    char f2[51];   
    strcpy(f2, PQgetvalue(res, i, 1));   
    printf("%d %s\n", f1, f2);   
    }   
    PQclear(res);   
    PQexec(con, "DEALLOCATE stmt_selectf1f2fromt1");   
      
   same code as C with embedded SQL:   
      
    EXEC SQL DECLARE mycursor CURSOR FOR SELECT f1,f2 FROM t1;   
    EXEC SQL OPEN mycursor;   
    for(;;)   
    {   
    EXEC SQL FETCH mycursor INTO :f1, :f2;   
    if(sqlca.sqlcode != 0) break;   
    printf("%d %s\n", f1, f2);   
    }   
    EXEC SQL CLOSE mycursor;   
      
   Simpler shorter code, because the pre-compiler handle   
   some of the plumbing.   
      
   Arne   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca