kylemaxxwell / rpostgresql

Automatically exported from code.google.com/p/rpostgresql
0 stars 0 forks source link

R crash following temporary table query #24

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
> x <- dbSendQuery(con, "CREATE TEMPORARY TABLE xyz ON COMMIT DROP AS select * 
from abc limit 1; select * from xyz;")
row number 0 is out of range 0..-1

 *** caught segfault ***
address (nil), cause 'memory not mapped'

Traceback:
 1: .Call("RS_PostgreSQL_exec", conId, statement, PACKAGE = .PostgreSQLPkgName)
 2: postgresqlExecStatement(conn, statement, ...)
 3: is(object, Cl)
 4: is(object, Cl)
 5: .valueClassTest(standardGeneric("dbSendQuery"), "DBIResult",     "dbSendQuery")
 6: dbSendQuery(con, "CREATE TEMPORARY TABLE xyz1 ON COMMIT DROP AS select * from qsp limit 1; select * from xyz1;")

Possible actions:
1: abort (with core dump, if enabled)
2: normal R exit
3: exit R without saving workspace
4: exit R saving workspace
Selection: 

Package:            RPostgreSQL
Version:            0.1-6
Date:               $Date: 2009-10-19 16:04:18 -0500 (Mon, 19 Oct 2009) $
> R.version
               _                            
platform       x86_64-unknown-linux-gnu     
arch           x86_64                       
os             linux-gnu                    
system         x86_64, linux-gnu            
status                                      
major          2                            
minor          11.1                         
year           2010                         
month          05                           
day            31                           
svn rev        52157                        
language       R                            
version.string R version 2.11.1 (2010-05-31)

Original issue reported on code.google.com by rmcge...@gmail.com on 22 Sep 2010 at 7:46

GoogleCodeExporter commented 9 years ago
Reproducible in r143

==== Running RPostgreSQL/tests/dbtemptable.R
Loading required package: RPostgreSQL
Loading required package: DBI
row number 0 is out of range 0..-1

 *** caught segfault ***
address (nil), cause 'memory not mapped'

Traceback:
 1: .Call("RS_PostgreSQL_exec", conId, statement, PACKAGE = .PostgreSQLPkgName)
 2: postgresqlExecStatement(conn, statement, ...)
 3: is(object, Cl)
 4: is(object, Cl)
 5: .valueClassTest(standardGeneric("dbSendQuery"), "DBIResult",     "dbSendQuery")
 6: dbSendQuery(con, "CREATE TEMPORARY TABLE xyz ON COMMIT DROP AS select * from foo limit 1; select * from xyz;")
aborting ...
check_with_vars.sh: line 42:  5871 Segmentation fault      R --slave < $f

A test script and a patch against r143 is attached.

The segmentation fault is caused by accessing the query result without
checking the existence of result.
A check for the number of tuples obtained is added.

The expected results is
==== Running RPostgreSQL/tests/dbtemptable.R
Loading required package: RPostgreSQL
Loading required package: DBI
  name
1  bar
PASS -- ended without segmentation fault

Original comment by tomoa...@kenroku.kanazawa-u.ac.jp on 24 Sep 2010 at 11:52

Attachments:

GoogleCodeExporter commented 9 years ago
Further thinking on the context of the location, the code is trying to identify 
if the column is set to NOT NULL or NULL value is allowed.  However, the NOT 
NULL enforcement is done by the server side and the necessity or even utility 
in the client side is questionable.

Perhaps, this is better discussed in r-db-sig@stat.math.ethz.ch, since this is 
related to DBI interface as a whole, including other drivers and usage.

I actually think these could be useful in a result for dbReadTable() call,
but not for general dbSendQuery or dbGetQuery results where the SQL is visible 
and the queried target may not represent a simple table.

Original comment by tomoa...@kenroku.kanazawa-u.ac.jp on 25 Sep 2010 at 2:30

Attachments:

GoogleCodeExporter commented 9 years ago
Reassigned owner.

Original comment by ne...@neiltiffin.com on 13 Oct 2010 at 2:18

GoogleCodeExporter commented 9 years ago
Fixed as of r160, r162.

Original comment by tomoa...@kenroku.kanazawa-u.ac.jp on 14 Oct 2010 at 2:41