Re: core dump using Pro*C on CONNECT

From: Bit Twister <BitTwister_at_localhost.localdomain>
Date: Wed, 30 Jul 2003 22:53:40 GMT
Message-ID: <slrnbigiuk.4p6.BitTwister_at_wb.home>


On Wed, 30 Jul 2003 20:44:11 +0000, thumor wrote:
>
> Originally posted by Bit Twister

>> On Wed, 30 Jul 2003 14:42:38 +0000, thumor wrote:
>> > 
>> > Thanks for the code, but there is basically no difference in the
>>     way
>> > I attempt to connect.
>>
>> All though what are saying is correct, you have overlooked that
>> we were trying to show you that the *.len vars need to set with
>> the length
>> of the *.arr string, which is incorrect.
>>
>> > What do you say to that??
>>
>> Fix the code with the .len set and post your code if still broke.
>> 

>
> I did the same, it did not work still.
> Here is the extract again:
>
>
> EXEC SQL INCLUDE SQLCA;
>
> EXEC SQL DECLARE DB_NAME DATABASE;
>
> EXEC SQL BEGIN DECLARE SECTION;
>
> varchar User_name[ 40 ];
> varchar User_pass[ 40 ];
> varchar User_db[40];
>
> EXEC SQL END DECLARE SECTION;
>
> main(int argc, char *argv)
> {
> strcpy(user_id, argv[2]);
> strcpy(user_pw, argv[3]);
> strcpy(db_name, argv[4]);
>
> strncpy( User_name.arr, user_id, sizeof(User_name.arr));
> User_name.len = strlen(user_id);
>
> strncpy( User_pass.arr, user_pw, sizeof(User_pass.arr));
> User_pass.len = strlen(user_pw);
>
> strncpy( User_db.arr, db_name, sizeof(User_db.arr));
> User_db.len = strlen(db_name);
>
> sprintf(Log_Msg,"Debug Level=%d",Debug_level);
> Log_Message(Main_Log, "main", INFORM, Log_Msg);
>
> sprintf(Log_Msg,"User name=%s, Pw=%s, DB=%s",user_id,
> user_pw, db_name);
> Log_Message(Main_Log, "main", INFORM, Log_Msg);
>
> sprintf(Log_Msg,"DB User name=%s, Pw=%s, DB=%s",User_name.arr,
> User_pass.arr, User_db.arr);
> Log_Message(Main_Log, "main", INFORM, Log_Msg);
>
> printf("\n Before Connected ..");
> EXEC SQL CONNECT :User_name IDENTIFIED BY :User_pass AT DB_NAME
> USING :User_db;
>
> printf("\n Connected ..");
>
> if (atoi(getenv("TEST"))==0)
> {
> Log_Message(Main_Log, "main", INFORM, "Started
> Production version");
> cc=scale_main();
> }
> else
> {
> Log_Message(Main_Log, "main", INFORM, "Started Test
> version");
> t_scale_main();
> };
>
> }
> /* End of main() */
>
>
> The functions scale_main() and t_scale_main() are part of the libraries
> that I link with.
>
> Please help.

Try making it as simple as possible, hardcode values. Sorry I cannot give working code, which will print oracle error message. Was layed off last month, but code should not core dump. Example:

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sqlda.h>
#include <sqlcpr.h>
#include <sqlca.h>

EXEC SQL BEGIN DECLARE SECTION ;
VARCHAR Username [50] ;
VARCHAR Userpass [50] ;
EXEC SQL END DECLARE SECTION; int main (void)
{

     Username.len = sprintf ((char *) Username.arr, "userid_here") ;
     Userpass.len = sprintf ((char *) Userpass.arr,
                                "passwd_here_at_database_here" ) ;

     EXEC SQL CONNECT :Username IDENTIFIED BY :Userpass ;

     if (sqlca.sqlcode != 0)
       printf ("failed\n") ;
     else
       printf ("passed\n") ;

     exit (0) ;

} Received on Thu Jul 31 2003 - 00:53:40 CEST

Original text of this message