google-code-export / sqljet

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

ISqlJetTable#insert works incorrectly if the first value is 'null' and the table's first field is a primary key #174

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

            final File databaseFile = new File(directory, "database.db");
            if (databaseFile.exists()) {
                databaseFile.delete();
            }
            final SqlJetDb sqlJetDb = SqlJetDb.open(databaseFile, true);
            ISqlJetTable table;
            try {
                sqlJetDb.createTable("CREATE TABLE MY_TABLE (id INTEGER NOT NULL PRIMARY KEY, field1 TEXT, field2 TEXT)");

                sqlJetDb.beginTransaction(SqlJetTransactionMode.WRITE);

                table = sqlJetDb.getTable("MY_TABLE");
                table.insert("value1", "value2");
                table.insert(null, "value2");
                sqlJetDb.commit();

                sqlJetDb.beginTransaction(SqlJetTransactionMode.READ_ONLY);
                table = sqlJetDb.getTable("MY_TABLE");
                final ISqlJetCursor cursor = table.open();
                int i = 0;
                while (!cursor.eof()) {
                    final String value1 = cursor.getString(1);
                    final String value2 = cursor.getString(2);

                    switch (i) {
                        case 0:
                            Assert.assertEquals("value1", value1);
                            Assert.assertEquals("value2", value2);
                            break;
                        case 1:
                            Assert.assertEquals(null, value1);
                            Assert.assertEquals("value2", value2);
                            break;
                        default:
                            break;
                    }

                    cursor.next();
                    i++;
                }
                sqlJetDb.commit();

            } finally {
                sqlJetDb.close();
            }

Original issue reported on code.google.com by dmi...@gmail.com on 15 Apr 2013 at 12:57

GoogleCodeExporter commented 9 years ago

Original comment by sergey.s...@gmail.com on 15 Apr 2013 at 1:08

GoogleCodeExporter commented 9 years ago
Is there still developement going on with sqljet?

I've been investigating this problem and there seems to be error in 
SqlJetBtreeDataTable function adjustRowIdPosition. 

Changed
if (primaryKeyColumnNumber >= 0 && primaryKeyColumnNumber < row.length && 
row[primaryKeyColumnNumber] != null) {

to
if (primaryKeyColumnNumber >= 0 && primaryKeyColumnNumber < row.length) {

and there is no issue anymore. Is there some reason for null check? Does this 
add other problems?

Original comment by ap.r...@gmail.com on 18 Jun 2014 at 7:30

GoogleCodeExporter commented 9 years ago
Thank you. I will look it more carefully.

Original comment by sergey.s...@gmail.com on 18 Jun 2014 at 1:06