pg.ddx.io  pgsql-odbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Jeremy Faith <jfaith@cemsys.com>
To: pgsql-odbc@postgresql.org
Subject: Re: SQLBulkOperations Segfault
Date: Mon, 21 Apr 2008 11:19:16 +0100
Message-ID: <480C6A24.6010008@cemsys.com> (raw)
In-Reply-To: <480AB639.2020502@tpf.co.jp>
References: <4808C57D.1080600@cemsys.com>
	<480AB639.2020502@tpf.co.jp>

Hiroshi Inoue wrote:
> Jeremy Faith wrote:
>> Hi,
>>
>> I have been experimenting with SQLBulkOperations to see if it is 
>> faster at inserting rows than using individual insert statements.
>> But when I run the attached(bo.c) example program it segfaults(note, 
>> this program works correctly with an Oracle ODBC connection).
>>
>> The program requires the following table.
>>  create table customer
>>  (
>>    cust_num integer not null,
>>    first_name char(20),
>>    last_name char(20)
>>  );
>>
>> Also the odb_db_open function call uses a hard coded DSN=pg_cdc_w, 
>> username=username and password=password.
>>
>> I am using the latest versions of pgsql+postgres on Linux i.e.
>>  psqlodbc-08.03.0100
>>  postgresql-8.3.1
>>
>> I turned on the ODBC debug log and added some log output to the 
>> driver and found that the segfault is occurring in the 
>> results.c:SC_pos_add function.
>>
>> In particular the log shows
>>  POS ADD fi=(nil) ti=(nil)
>>
>> and the segfault occurs on this line:-
>>                        if (*used != SQL_IGNORE && fi[i]->updatable)
>> So fi is NULL but is being referenced.
>>
>> I did a bit more checking and found that parse_statement sets up 
>> stmt->ird->irdopts.fi i.e.
>>        if (SC_update_not_ready(stmt))
>>                parse_statement(s.stmt, TRUE);  /* not preferable */
>> so adding
>>  fi=stmt->ird->irdopts.fi;
>> after parse_statement gets past this segfault.
>>
>> But then another segfault occurs in the results.c:positioned_load 
>> function as stmt->load_stmt is NULL
>>  so strlen(stmt->load_stmt) segfaults.
>>
>> The code is complicated and I have not been able to determine how to 
>> fix this, it seems likely to me that even the fi fix may be covering 
>> up an earlier problem somewhere else in the code.
>
> Before calling SQLExecDirect(), please set the SQL_ATTR_CURSOR_TYPE
> to SQL_CURSOR_STATIC or SQL_CURSOR_KEYSET_DRIVER and also set the
> SQL_ATTR_CONCURRENCY to SQL_CONCUR_ROWVER.
>
That fixes it, thanks.

Perhaps SQLBulkOperations could check that these attributes are set 
correctly and return an ODBC error if not. It is not clear from any ODBC 
documentation that I have read that these need to be set this way to do 
an SQL_ADD.

I have done a speed test and have found that the SQLBulkOperations 
method takes about twice as long as using a prepared insert. So as it is 
faster and easier the prepared insert seems to be the way to go.

Using the prepared insert method, the old driver included with unixODBC 
is considerably faster than psqlodbcw, any idea why?
Is there any problem with using the old driver?

Regards,
Jeremy Faith



view thread (3+ messages)

Message-ID: <480C6A24.6010008@cemsys.com>
Permalink:  ../480C6A24.6010008@cemsys.com/
Also on:    postgresql.org/message-id/480C6A24.6010008@cemsys.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-odbc@postgresql.org
  Cc: jfaith@cemsys.com
  Subject: Re: SQLBulkOperations Segfault
  In-Reply-To: <480C6A24.6010008@cemsys.com>
  References: <4808C57D.1080600@cemsys.com> <480AB639.2020502@tpf.co.jp> <480C6A24.6010008@cemsys.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox