Re: Writing UDR C Routine
Posted in 2000
Topics: Installation, Setup & Upgrades, Stored Procedures & SPL, Connectivity: ESQL/C, 4GL & Embedded SQL, Server Administration, Data Types & Schema Design, Platform-Specific Issues, Versions, Editions & End-of-Life
Andrea Verni wrote:
>
> Hi gurus,
>
> I need to write some simple UDR using C language on:
>
> - Linux SuSE 6.2
> - Internet Foundation.2000 (IDS 9.20-UC1)
> - GNU ld version 2.9.5 (with BFD 2.9.5.0.24)
> - gcc version 2.95.2 19991024 (release)
> - glib-1.2.so.0.0.7
What version of the regular C library are you using (ls -l /lib/libc*)? That
glib library is from the Gnome stuff I think.
> I can compile a simple code to connect to db but when I run the
> executable I get a segmentation fault due to this error:
What was your comple line? What libs did you specify? Do you have
Client SDK installed?
> # gdb connect
> Starting program: /home/prjdba/c/connect
>
> Program received signal SIGSEGV, Segmentation fault.
> 0x40292b18 in pthread_mutex_lock () at mutex.c:75
> 75 mutex.c: No such file or directory.
> (gdb)
>
> .. this is the code:
>
> #include "mi.h"
> #include <stdio.h>
>
> main ()
> {
> MI_CONNECTION *conn;
>
> conn = mi_open("dbname","user","pass");
> {
> printf("cannot open db connection\\n");
> exit(3);
> }
>
> mi_close(conn);
> exit(0);
> }
You are missing some code but since you don't seem to be getting past the
mi_open() it's a moot point:
MI_CONNECTION *conn;
if (conn = mi_open("dbname","user","pass"))
{
printf("cannot open db connection\\n");
exit(3);
}
if (conn)
mi_close(conn);
> Any hints? Does anyone has already wrote some UDR using Datablade API
> on Linux platform?
The above is a client program, not a UDR. Although the libdmi calls you
are using can be used in a client it is better to use something more
appropriate like ESQL/C.
If you want a simple UDR example try this.
hello.c:
#include "mi.h"
mi_lvarchar *
hello ()
{
mi_lvarchar *v;
if ((v = mi_string_to_lvarchar ("Hello World")) == NULL)
{
mi_db_error_raise (NULL, MI_EXCEPTION, "could not convert string");
}
return (v);
}
Compile with:
gcc -fpic -c -DLINUX -I$(INFORMIXDIR)/incl/public hello.c
ld -shared hello.o -o hello.so
Register with the following SQL (change the path name as appropriate):
create function hello () returning lvarchar
with (not variant)external name '/home/informix/9.21/blades/hello/hello.so(hello)'
language c;
Then test with:
execute function hello();
Cosmo