Swipl ODBC bug

I’m using:

  • SWI-Prolog version 64 bits, version 8.1.10 on macOS Mojave 10.14.6.;
  • UnixODBC version 2.3.7;
  • psqlODBC v11.01;
  • Postgres 11.4;
  • Swipl ODBC package.

I am trying to insert into Postgres database 11.4, but I find it very difficult to debug. For example, when I made a mistake by trying to insert varchar type value into an integer type column, Swipl does not return any error it just kills the shell and exits. I tried to trace, but it is no good. Just to clarify, connections work and I can insert into the database fine when the query is correct. But I am a bit worried, because when some error occurs it does not return any error code and just kills the shell. Maybe it is because of my operating system or because I am using newer versions of Postgres? At this point, I am not able to test it on another operating system. It looks like external library is crashing, and I am wondering why.

But what I’m getting is:

SWI-Prolog [thread 1 (main) at Fri Aug  2 08:42:21 2019]: received fatal signal 11 (segv)

C-stack trace labeled “crash”:
[0] /Users/dz361/lib/swipl/lib/x86_64-darwin/libswipl.8.dylib(save_backtrace+0xee) [0x101cced8e]
[1] /Users/dz361/lib/swipl/lib/x86_64-darwin/libswipl.8.dylib(sigCrashHandler+0xb2) [0x101ccf342]
[2] /Users/dz361/lib/swipl/lib/x86_64-darwin/libswipl.8.dylib(dispatch_signal+0x233) [0x101c59b83]
[3] /usr/lib/system/libsystem_platform.dylib(_sigtramp+0x1d) [0x7fff6fed7b5d]
[4] /usr/lib/system/libsystem_malloc.dylib(szone_malloc_should_clear+0x42) [0x7fff6fe9820f]
sh: addr2line: command not found
[5] /Library/PostgreSQL/psqlODBC/lib/psqlodbcw.so(PGAPI_GetDiagRec+0x236) [0x102038b96]
[6] /Library/PostgreSQL/psqlODBC/lib/psqlodbcw.so(SQLGetDiagRec+0xe0) [0x102037500]
[7] /usr/local/opt/unixodbc/lib/libodbc.2.dylib(extract_diag_error+0x7fa) [0x101f29439]
[8] /usr/local/opt/unixodbc/lib/libodbc.2.dylib(function_return_ex+0x8f) [0x101f2a2c0]
[9] /usr/local/opt/unixodbc/lib/libodbc.2.dylib(SQLExecDirect+0x3e5) [0x101f00aff]
[10] /Users/dz361/lib/swipl/lib/x86_64-darwin/odbc4pl.so(pl_odbc_query+0x1c7) [0x101ee24d7]
[11] /Users/dz361/lib/swipl/lib/x86_64-darwin/libswipl.8.dylib(PL_next_solution+0xd247) [0x101bde477]
[12] /Users/dz361/lib/swipl/lib/x86_64-darwin/libswipl.8.dylib(query_loop+0x141) [0x101c38c41]
[13] /Users/dz361/lib/swipl/lib/x86_64-darwin/libswipl.8.dylib(prologToplevel+0x51) [0x101c392e1]
[14] /Users/dz361/lib/swipl/lib/x86_64-darwin/libswipl.8.dylib(PL_toplevel+0x38) [0x101bf5308]
[15] /Users/dz361/bin/./swipl(main+0x25) [0x101bbcf65]
[16] /usr/lib/system/libdyld.dylib(start+0x1) [0x7fff6fcec3d5]
Running on_halt hooks with status 139
Killing 52924 with default signal handlers
My code looks like this:

% This is just an example code, In reality it is more complex.
odbc_connect('PostGSQL', Connection, [user(USERNAME), password(PASSWORD)]),
odbc_query(Connection, 'INSERT INTO public.testing_table(test_column) VALUES(\'Hello\')', Affected).

If you built SWI-Prolog from source, please rebuild it for debugging and run under gdb/lldb or some memory debugger. The crash suggests a memory management issue. Given the stack trace my first suspect would be the postgress ODBC driver, but one never knows.

It is a bit hard to help as setting up all the requirements to reproduce looks like a lot of work. I’m always struggling with setting up a database as well as ODBC and not too familiar with the MacOS development tools. A description on how to set it all up might help …

@jan Thanks for the advice, but as it turned out, the fault was in ODBC driver itself. Hard to pinpoint what was the exact issue, but when I rebuilt driver from source, everything works as a charm!

1 Like