# Swipl ODBC bug

**URL:** <https://swi-prolog.discourse.group/t/swipl-odbc-bug/1022>\
**Category:** Help!\
**Tags:** bug\
**Created:** [August 2, 2019, 5:49am UTC](https://swi-prolog.discourse.group/t/swipl-odbc-bug/1022 "2019-08-02T05:49:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![oskarstreimanis](https://avatars.discourse-cdn.com/v4/letter/o/b5a626/32.png) [@oskarstreimanis](https://swi-prolog.discourse.group/u/oskarstreimanis)\
**Post date:** [August 2, 2019, 5:49am UTC](https://swi-prolog.discourse.group/t/swipl-odbc-bug/1022/1 "2019-08-02T05:49:43Z")

</div>

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.

Hello,  
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:

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

```

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [August 2, 2019, 8:21am UTC](https://swi-prolog.discourse.group/t/swipl-odbc-bug/1022/2 "2019-08-02T08:21:59Z")

</div>

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 …

---

<div class="post-metadata">

**Author:** ![oskarstreimanis](https://avatars.discourse-cdn.com/v4/letter/o/b5a626/32.png) [@oskarstreimanis](https://swi-prolog.discourse.group/u/oskarstreimanis)\
**Post date:** [August 12, 2019, 5:30am UTC](https://swi-prolog.discourse.group/t/swipl-odbc-bug/1022/3 "2019-08-12T05:30:16Z")

</div>

@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!
