embedded SQL problem 
Author Message
 embedded SQL problem

when i am using embeded SQL to write statement, e.g. INSERT.  If I use
CGI to get the result from the user in the web, so that I don't know the
table name before hand.

so i write the code as follows:

============================begin=====================================
void insert(int fieldNo, char tName[], char field[][MAXFLEN])
{
        EXEC SQL BEGIN DECLARE SECTION;
                char *tmpTName;
                char **tmpField;
        EXEC SQL END DECLARE SECTION;

        tmpTName = tName;
        tmpField = field;

        EXEC SQL INSERT INTO :tmpTName VALUES (:tmpField[1]);

        . . .

Quote:
}

============================END====================================

the variable "tmpTName" is a reference to the table name.  But when i
cpre it, error like

M_SYNTAX_PARSE,Syntax error in file db1.cp, at line: 245 near <:>

appeared.  The line with the command insert is on line 245.

Thanks!
Pls help me.  Urgent!



Mon, 24 Apr 2000 03:00:00 GMT
 embedded SQL problem


Quote:
>when i am using embeded SQL to write statement, e.g. INSERT.  If I use
>CGI to get the result from the user in the web, so that I don't know the
>table name before hand.
>        EXEC SQL INSERT INTO :tmpTName VALUES (:tmpField[1]);

Don't know about CGI, but statements like these will probably have to
be executed dynamically. Try to use 'EXECUTE IMMEDIATE' in conjunction
with a character string containing the entire insert statement.

Good luck

Jean-Marc.
+------------------------------------------------------------+

|ingbank.com           | opinions (and my personal ones!).   |
+-- (AntiSpam:note the xxremovexx in the reply-to address) --+



Mon, 24 Apr 2000 03:00:00 GMT
 embedded SQL problem


Quote:

> >when i am using embeded SQL to write statement, e.g. INSERT.  If I use
> >CGI to get the result from the user in the web, so that I don't know the
> >table name before hand.
> >        EXEC SQL INSERT INTO :tmpTName VALUES (:tmpField[1]);
> Don't know about CGI, but statements like these will probably have to
> be executed dynamically. Try to use 'EXECUTE IMMEDIATE' in conjunction
> with a character string containing the entire insert statement.

First of all, thanks for your help.  But my problem is when I
pre-compile the code, error occured.  Now, my aim is to solve it.  Can
you all help me?

Thanks!



Tue, 25 Apr 2000 03:00:00 GMT
 embedded SQL problem


Quote:


>> >when i am using embeded SQL to write statement, e.g. INSERT.  If I use
>> >CGI to get the result from the user in the web, so that I don't know the
>> >table name before hand.
>> >        EXEC SQL INSERT INTO :tmpTName VALUES (:tmpField[1]);
>> Don't know about CGI, but statements like these will probably have to
>> be executed dynamically. Try to use 'EXECUTE IMMEDIATE' in conjunction
>> with a character string containing the entire insert statement.
>First of all, thanks for your help.  But my problem is when I
>pre-compile the code, error occured.  Now, my aim is to solve it.  Can
>you all help me?

What I meant is do something like:

tmpSQL = 'INSERT INTO fooBar values( 12);'

EXEC SQL IMMEDIATE USING :tmpSQL ;

Or something along those lines. If this works, you can then modify the
assignment to be more flexible like

tmpSQL = 'INSERT INTO ' + tmpTName + ' VALUES (' + tmpField[1] + ');'

HTH

Jean-Marc.
+------------------------------------------------------------+

|ingbank.com           | opinions (and my personal ones!).   |
+-- (AntiSpam:note the xxremovexx in the reply-to address) --+



Sat, 29 Apr 2000 03:00:00 GMT
 embedded SQL problem


Quote:

> >when i am using embeded SQL to write statement, e.g. INSERT.  If I use
> >CGI to get the result from the user in the web, so that I don't know the
> >table name before hand.
> >        EXEC SQL INSERT INTO :tmpTName VALUES (:tmpField[1]);
> Don't know about CGI, but statements like these will probably have to
> be executed dynamically. Try to use 'EXECUTE IMMEDIATE' in conjunction
> with a character string containing the entire insert statement.

Oh, thanks a lot!  It works well.  Sorry for my misunderstanding.  Once
again, thank for very much!


Sat, 29 Apr 2000 03:00:00 GMT
 
 [ 5 post ] 

 Relevant Pages 

1. embedded SQL:Problem during compilation in embedded sql(MSSQL) with VC++

2. Embedded SQL problems

3. Embedded SQL problem

4. Embedded SQL problem

5. Embedded SQL problem

6. Embedded SQL Problem: Cursor, Fetch

7. strange embed SQL problem

8. embedded sql problem

9. Strange stored proc/embedded SQL problem

10. System10 with Dynamic embedded sql problem

11. embedded sql problem with INDICATOR

12. Embedded SQL problem


 
Powered by phpBB® Forum Software