- 
    Type:
Bug
 - 
    Resolution: Fixed
 - 
    Priority:
  P4                     
     - 
    Affects Version/s: 1.0, 6
 - 
    Component/s: core-libs
 
- 
        b04
 - 
        generic
 - 
        generic
 - 
        Not verified
 
                    In further testing, I have come upon a new bug.  This one happens only in CachedRowSet updates.  It is creating an UPDATE statement which contains a syntax error.  I created a small example where I can reproduce the problem:
First, I set up a table and inserted one record.
CREATE TABLE crs_test (
orgid int4,
id serial NOT NULL UNIQUE PRIMARY KEY,
username varchar(40) NULL UNIQUE,
password varchar(30) NULL,
deletedFlag int2 default 0,
anotherint int4 NULL
);
INSERT INTO crs_test (username,password,deletedflag) VALUES ('testcrs','password',0);
Next, I ran the following query using the CachedRowSet (I used a prepared statement setting ? to "testcrs").
select * from crs_test where username=?
Finally, I tried to update a value on the CachedRowSet (I set the username to 'testcrschanged') and then I save the changes. This results in the following error.
PSQLException: ERROR: syntax error at or near "username"
I checked the database logs, and this is the UPDATE statement that the CachedRowSet had executed:
UPDATE crs_test SET orgid = null username = 'testchanged' , anotherint = null WHERE orgid IS NULL AND id = 1 AND username = 'testcrs' AND password = 'password' AND deletedflag = 0 AND anotherint IS NULL
The syntax problem is a comma which is missing between "orgid = null" and "username = 'testchanged'". I have encountered this same problem with most other queries we perform. I couldn't narrow it down completely, but it seems to always happen after a column whose value is NULL. I have been able to execute a successful update by removing any columns with NULL values from the original query.
            
First, I set up a table and inserted one record.
CREATE TABLE crs_test (
orgid int4,
id serial NOT NULL UNIQUE PRIMARY KEY,
username varchar(40) NULL UNIQUE,
password varchar(30) NULL,
deletedFlag int2 default 0,
anotherint int4 NULL
);
INSERT INTO crs_test (username,password,deletedflag) VALUES ('testcrs','password',0);
Next, I ran the following query using the CachedRowSet (I used a prepared statement setting ? to "testcrs").
select * from crs_test where username=?
Finally, I tried to update a value on the CachedRowSet (I set the username to 'testcrschanged') and then I save the changes. This results in the following error.
PSQLException: ERROR: syntax error at or near "username"
I checked the database logs, and this is the UPDATE statement that the CachedRowSet had executed:
UPDATE crs_test SET orgid = null username = 'testchanged' , anotherint = null WHERE orgid IS NULL AND id = 1 AND username = 'testcrs' AND password = 'password' AND deletedflag = 0 AND anotherint IS NULL
The syntax problem is a comma which is missing between "orgid = null" and "username = 'testchanged'". I have encountered this same problem with most other queries we perform. I couldn't narrow it down completely, but it seems to always happen after a column whose value is NULL. I have been able to execute a successful update by removing any columns with NULL values from the original query.