Thread: Using embedded SQL.

Using embedded SQL.

From
"Robert J. Sprawls"
Date:
Hello,
    I'm trying to learn embedded SQL in C. However, it's not working
and reading the documentation is not answering my question(s). Here is my
code:

#include <stdlib.h>
#include <stdio.h>
exec sql include sqlca;

int main( int argc, char *argv[] ) {

   exec sql whenever sqlerror sqlprint;
   exec sql connect tootle;
   exit( 0 );
   exec sql disconnect sprawlsr;
}

And here is what I get back:

sql error Could not connect to database <DEFAULT> in line 25.

What am I doing wrong? Yes, the database does exist as tootle.

Robert



Compiling Error

From
Jesus Aneiros
Date:
Hi,

Could somebody help me with this error. It appears when I try to compile
an ecpg program. It seems that it is something with the linking phase and
the ecpg library. Any ideas?

/usr/lib/libecpg.so: undefined reference to `crypt'
collect2: ld returned 1 exit status

Best regards, Jesus.


Re: Compiling Error

From
Tom Lane
Date:
Jesus Aneiros <aneiros@jagua.cfg.sld.cu> writes:
> Could somebody help me with this error. It appears when I try to compile
> an ecpg program. It seems that it is something with the linking phase and
> the ecpg library. Any ideas?

> /usr/lib/libecpg.so: undefined reference to `crypt'
> collect2: ld returned 1 exit status

You probably need an explicit "-lcrypt" in your link command.  Some
platforms need that, some don't...

            regards, tom lane

Re: Compiling Error

From
Charles Tassell
Date:
You aren't including the crypt library, or your system doesn't have
it.  Try adding
-lcrypt
  to the end of your compile command and try again.

At 12:44 PM 6/4/00, Jesus Aneiros wrote:
>Hi,
>
>Could somebody help me with this error. It appears when I try to compile
>an ecpg program. It seems that it is something with the linking phase and
>the ecpg library. Any ideas?
>
>/usr/lib/libecpg.so: undefined reference to `crypt'
>collect2: ld returned 1 exit status
>
>Best regards, Jesus.


Re: Compiling Error

From
Michael Meskes
Date:
On Sun, Jun 04, 2000 at 11:44:36AM -0400, Jesus Aneiros wrote:
> an ecpg program. It seems that it is something with the linking phase and
> the ecpg library. Any ideas?
>
> /usr/lib/libecpg.so: undefined reference to `crypt'
> collect2: ld returned 1 exit status

Try adding -lcrypt to your link command. I take it your system tuns glibc2.
:-)

Michael
--
Michael Meskes
Michael@Fam-Meskes.De
Go SF 49ers! Go Rhein Fire!
Use Debian GNU/Linux! Use PostgreSQL!

Re: Using embedded SQL.

From
Michael Meskes
Date:
On Sat, Jun 03, 2000 at 05:37:32PM -0500, Robert J. Sprawls wrote:
>     I'm trying to learn embedded SQL in C. However, it's not working
> and reading the documentation is not answering my question(s). Here is my

Please check the test cases in the source tree. They help a little bit.

> #include <stdlib.h>
> #include <stdio.h>
> exec sql include sqlca;
>
> int main( int argc, char *argv[] ) {
>
>    exec sql whenever sqlerror sqlprint;
>    exec sql connect tootle;

The correct syntax is

exec sql connect to tootle;

>    exit( 0 );
>    exec sql disconnect sprawlsr;

Sorry, I do not understand that line. At first your program will never
disconnect from that database since it exists before it can execute that
statement. And second you never connected to sprawlsr so how can you
dissconnect?

> }
>
> And here is what I get back:
>
> sql error Could not connect to database <DEFAULT> in line 25.
>
> What am I doing wrong? Yes, the database does exist as tootle.

Yup, that's one of those Oracle compatibility hacks. If you use connect
without 'to' ecpg expects the following term to a oracle like user
specification.

Michael
--
Michael Meskes
Michael@Fam-Meskes.De
Go SF 49ers! Go Rhein Fire!
Use Debian GNU/Linux! Use PostgreSQL!