4 Replies Latest reply: May 9, 2012 10:59 PM by 935988 RSS

    SQL with Berkeley DB

    931411
      Hi Guys ,

      I am developing an iPhone application which uses BDB as the storing mechanism and I am trying to access BDB using sqlite3.
      The problem occurs when I try to create a table on the DB , it's giving me an error with description "file is encrypted or is not a database". I am creating the database using the provided db_create function and I can open the created database without any errorsl . It would great someone can enlighten us about this issue.
        • 1. Re: SQL with Berkeley DB
          Laurenfoutz-Oracle
          You cannot access a DB database created by db_create using sqlite3, or the Berkeley DB SQL API. If you want to create a database that can be accessed by the SQL API in BDB, you have to use either the shell, dbsql, or use sqlite3_open in an application linked to the Berkeley DB SQL library. Also note that database created by SQLite cannot be accessed by Berkeley DB SQL, and visa versa.

          Lauren Foutz
          • 2. Re: SQL with Berkeley DB
            935988
            Hi Lauren,

            I manage to access the Database as you instructed. Thank you very much for that. Unfortunately Im still running to some issues. The main issue I have is that when I try to read values of a Integer primary key using sqlite3_column_int I receive a invalid integer.

            eg
            Actual Value in the database - 1
            Value returned - 1162104322

            However retrieving strings and other integers are not an issue.

            Any insight to the problem is much appreciated
            • 3. Re: SQL with Berkeley DB
              Laurenfoutz-Oracle
              What version of the Berkeley DB SQL library are you using? Also, can you post code that reproduces the issue?

              Lauren Foutz
              • 4. Re: SQL with Berkeley DB
                935988
                The version of the berkley DB is Berkeley DB 11gR2 (11.2.5.3.15) . It was built for iOS 5.1 using the following commands.

                export DEV_iOS=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer
                export SDK_iOS=${DEV_iOS}/SDKs/iPhoneSimulator5.1.sdk
                export COMPILER_iOS=${DEV_iOS}/usr/bin
                export CC=${COMPILER_iOS}/gcc
                export CXX=${COMPILER_iOS}/g++
                export LDFLAGS="-arch i686 -pipe -Os -gdwarf-2 -no-cpp-precomp -mthumb -isysroot ${SDK_iOS}"
                export CFLAGS=${LDFLAGS}
                export CXXFLAGS=${LDFLAGS}
                export LD=${COMPILER_iOS}/ld
                export CPP=${COMPILER_iOS}/cpp
                export AR=${COMPILER_iOS}/ar
                export AS=${COMPILER_iOS}/as
                export NM=${COMPILER_iOS}/nm
                export CXXCPP=${COMPILER_iOS}/cpp
                export RANLIB=${COMPILER_iOS}/ranlib

                ../dist/configure host=i686-apple-darwin10 with-cryptography=no enable-shared=no enable-sql --prefix=/Users/eurcolkwi/Documents/workspace/corena/mac_build/build_output

                make install


                The code

                if (sqlite3_open( [DATABASE_PATH UTF8String], &database) == SQLITE_OK)
                {
                NSLog(@"path --- %@", DATABASE_PATH );

                const char *sql = "SELECT SystemId FROM Cdm_CSDB";

                sqlite3_stmt *selectstmt;

                if(sqlite3_prepare_v2(database, sql, -1, &selectstmt, NULL) != SQLITE_OK)
                NSAssert1(0, @"Error. '%s'", sqlite3_errmsg(database));


                while (sqlite3_step(selectstmt) == SQLITE_ROW) {
                NSInteger a = sqlite3_column_int(selectstmt,0);

                sqlite3_int64 b = sqlite3_column_int(selectstmt,0);

                sqlite3_int64 c = sqlite3_column_int64(selectstmt,0);

                NSLog(@"error %i", sqlite3_extended_errcode(database));

                NSLog(@"column name RefID = %i",sqlite3_column_int(selectstmt,0));
                }


                sqlite3_finalize(selectstmt);

                sqlite3_close(database);
                } else {
                NSAssert1(0, @"An error occured while retrieving a record: '%s'", sqlite3_errmsg(database));
                }


                Im trying to access a berkley DB that is created using the berkley DB JDBC interface. I have no problem with accessing non primary key columns. Also when I create a new table in the DB and when I access a primary key column I get correct values.

                Thank you very much for your help