Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Contributor
Posts: 30
Registered: ‎03-24-2011
My Device: 9800
My Carrier: sfr
Accepted Solution

Sqlite problem under os 5 but works fine under os 6

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.

 

Contributor
Posts: 30
Registered: ‎03-24-2011
My Device: 9800
My Carrier: sfr

Re: Sqlite problem under os 5 but works fine under os 6

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.

Developer
Posts: 1,650
Registered: ‎04-08-2010
My Device: Z10 (red Limited Edition), Q10, Z30
My Carrier: Telekom.de, O2, Vodafone

Re: Sqlite problem under os 5 but works fine under os 6

I'm using SQLite Database Browser on OSX:

http://sourceforge.net/projects/sqlitebrowser/

 

never had problems using db from BB OS5 or OS 6

-------------------------------------------------------------------------------
ekke (independent software architect, rosenheim, germany)

BlackBerry Elite Developer
BlackBerry Platinum Enterprise Partner
International Development Mobile Apps BlackBerry 10 Cascades
Cascades - Workshops / Trainings / Bootcamps

blog: http://ekkes-corner.org videos: http://www.youtube.com/user/ekkescorner http://vimeo.com/ekkescorner/videos
bb10-development: http://appbus.org Twitter: @ekkescorner
Contributor
Posts: 30
Registered: ‎03-24-2011
My Device: 9800
My Carrier: sfr

Re: Sqlite problem under os 5 but works fine under os 6

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.