Using embedded SQL.

Started by Robert J. Sprawlsalmost 26 years ago6 messagesgeneral
Jump to latest
#1Robert J. Sprawls
sprawlsr@worldnet.att.net

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

#2Jesus Aneiros
aneiros@jagua.cfg.sld.cu
In reply to: Robert J. Sprawls (#1)
Compiling Error

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.

#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: Jesus Aneiros (#2)
Re: Compiling Error

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

#4Charles Tassell
ctassell@isn.net
In reply to: Jesus Aneiros (#2)
Re: Compiling Error

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:

Show quoted text

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.

#5Michael Meskes
meskes@postgresql.org
In reply to: Robert J. Sprawls (#1)
Re: Using embedded SQL.

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!

#6Michael Meskes
meskes@postgresql.org
In reply to: Jesus Aneiros (#2)
Re: Compiling Error

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!