04-26-2011 09:45 AM
Hi all !
I have a problem with my code while executing under Curve 8520 with os 5.0.0.1036 (last available for 8520). I am using a sqlite database and all my code works fine under os 6 in a torch 9800.
But in the 8520, I get an exception sying that I am trying to write in a read only database.
Here is my code to initialize the database :
private DbManager() throws Exception
{
// Determine if an SDCard is present
boolean sdCardPresent = false;
String root = null;
Enumeration e = FileSystemRegistry.listRoots();
while (e.hasMoreElements())
{
root = (String)e.nextElement();
if(root.equalsIgnoreCase("sdcard/"))
{
sdCardPresent = true;
}
}
if(!sdCardPresent)
{
this.db = null;
UiApplication.getUiApplication().invokeLater(new Runnable()
{
public void run()
{
// TODO : translate
Dialog.alert("The application requires a SDCard to store the history. Without card, your history will not be stored.");
}
});
}
else
{
dbLocation = "/SDCard/databases/"+BUNDLE_NAME+"/";
// Create URI
URI uri = URI.create(dbLocation + DB_NAME);
// Open or create a plain text database. This will create the
// directory and file defined by the URI (if they do not already exist).
db = DatabaseFactory.openOrCreate(uri);
// Close the database in case it is blank and we need to write to the file
db.close();
// Open a connection to the database file
FileConnection fileConnection = (FileConnection)Connector.open("file://" + dbLocation + DB_NAME);
// If the file is blank, copy the pre-defined database from this
// module to the SDCard.
if(fileConnection.exists() && fileConnection.fileSize() == 0)
{
readAndWriteDatabaseFile(fileConnection);
}
// Open the database
db = DatabaseFactory.open(uri);
}
}
And here is the statement that works with os 6 but not with os 5 :
public Integer create(Table table)
{
long id = -1;
try
{
Statement statement = this.db.createStatement("INSERT INTO ZTABLE(" + Table.TABLE_PK +
"," + Table.TABLE_LONGITUDE +
"," + Table.TABLE_DATE +
"," + Table.TABLE_LATITUDE) VALUES (null,?1,?2,?3)");
statement.prepare();
statement.bind(1, table.getLongitude().floatValue());
statement.bind(2, table.getDate().getTime());
statement.bind(3, table.getLatitude().floatValue());
statement.execute();
statement.close();
// Retrieve the auto-generated ID of the item just added
id = this.db.lastInsertedRowID();
}
catch(DatabaseException dbe)
{
CommonTools.errorDialog(dbe.toString());
}
return new Integer((int) id);
}
Is there any issue concerning the os 5 and the sqlite functionnality ? Or is there something wrong in my code that avoids a correct behaviour ?
Many thanks in advance for your answers.
Solved! Go to Solution.
04-26-2011 12:27 PM
I found some informations concerning the GUI manager used to create the sqlite database.
I use the last version of the great sqlite manager from firefox, I tried with Lita, but without success.
The DatabaseException still remains.
Does anybody have any idea of what to do ? What is the best GUI manager to use to create sqlite databases that work under os 5 devices ?
Thanks.
04-26-2011 12:49 PM
I'm using SQLite Database Browser on OSX:
http://sourceforge.net/projects/sqlitebrowser/
never had problems using db from BB OS5 or OS 6
04-27-2011 03:39 AM
Right, it seems that it solved my problem.
I totally rewrote my database, using sqlitebrowser for osx. I also cleaned some tables that where not used anymore (I used a database from an existing iOS project that I am rewriting for Blackberry).
Many thanks for that help.