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

Native Development

Reply
Contributor
Posts: 27
Registered: ‎02-28-2013
My Device: device
My Carrier: device
Accepted Solution

Database Connections.

Hi ,

 

I am New to Blackberry 10 Development.I have worked in sql Database to get the datas from the db and try to display it in the listview.But I could not able to get it.I have created a folder called sql ,I kept contacts.sql inside the folder with one table called contact with some datas. I have added LIBS += -lbb data in the .pro file and included #include <bb/data/DataSource> in the cpp file.Here the following codes of qml-----

===============

import bb.cascades 1.0
import bb.data 1.0

Page {
content: ListView {
id: myListView
dataModel: dataModel
listItemComponents: [
ListItemComponent {
type: "item"
StandardListItem {
title: ListItemData.firstname + " " + ListItemData.lastname
description: ListItemData.title
}
}
]
//...
}
attachedObjects: [
GroupDataModel {
id: dataModel
},
DataSource {
id: dataSource
source: "sql/contacts.sql"
query: "select * from contact order by firstname, lastname"
onDataLoaded: {
dataModel.insertList(data);
}
}
]
onCreationCompleted: { dataSource.load(); }
}

 

===============

 

Kindly review the qml and give me the solution.

 

Thanks & Regards,

Venkatesan.R

Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: Database Connections.

[ Edited ]

Can you post exactly what problem it is you are getting?

I.e. list is created but items not showing up or QML error

 

Have you actually created the SQL file, made sure the path and name are right and that you actually have records returned.

 

From the SQL app you used to create the contacts.sql database, if you enter that query does it return results?

 

Note that if you intend to write to this database you will need to copy it into the data folder first and alter the above qml accordingly.


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
Contributor
Posts: 27
Registered: ‎02-28-2013
My Device: device
My Carrier: device

Re: Database Connections.

Hi,

 

Thanks for your kind reply.They  displayed  the blank white screen and does not showing up.using Mysql I have created the database and put inside the sql folder.Kindly give me the path that I am using contacts.sql  datbase to display the item in the list.

 

Thanks and Regards,

Venkatesan.R

Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: Database Connections.

[ Edited ]

Your path is correct for accessing a readonly sqlite database from the assets folder.

 

I suspect if you look at your log output you'll find an SQL error in there somewhere.

 

There are differences in formats between MySql and SQlite can I recommend you create your database with something like SQLite browser or sqlitestudio. I have used both but find the more powerful features of sqlitestudio suits my needs better.

 

 


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
Highlighted
Developer
Posts: 27
Registered: ‎12-11-2012
My Device: Blackberry Z10
My Carrier: Viettel

Re: Database Connections.

You need to make sure your qml file is in assets folder. If it in a sub-folder, you have to add "asset:///" before "sql/"
Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: Database Connections.

[ Edited ]

@nhuanvd both absolute and relative paths should be fine.

 

However one more check occurs when I read your post, you have placed the ListView QML in the top level of the assets folder right? If that is also in a subfolder you will need to qualify it as nhuanvd says.

 

 

 

 


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
Contributor
Posts: 27
Registered: ‎02-28-2013
My Device: device
My Carrier: device

Re: Database Connections.

Hi All,

 

Thanks for your kind reply.I have added source: "asset:///sql/contacts.sql".But I couldn't get the result in the listview.please give me the solution.I have added LIBS += -lbbdata in the .pro file and also in my qmlsignal.cpp added the #include <bb/data/DataSource>The below qml file =======

===============

import bb.cascades 1.0
import bb.data 1.0

Page {
content: ListView {
id: myListView
dataModel: dataModel
listItemComponents: [
ListItemComponent {
type: "item"
StandardListItem {
title: ListItemData.firstname + " " + ListItemData.lastname
description: ListItemData.title
}
}
]
//...
}
attachedObjects: [
GroupDataModel {
id: dataModel
},
DataSource {
id: dataSource
source: "asset:///sql/contacts.sql"
query: "select * from contact order by firstname, lastname"
onDataLoaded: {
dataModel.insertList(data);
}
}
]
onCreationCompleted: { dataSource.load(); }
}

==============

 

Thanks & Regards,

Venkatesan.R

Contributor
Posts: 27
Registered: ‎02-28-2013
My Device: device
My Carrier: device

Re: Database Connections.

Hi,

 

Thanks for your kind reply.I have added source: "asset:///sql/contacts.sql".But I couldn't get the result in the listview.please give me the solution.I have added LIBS += -lbbdata in the .pro file and also in my qmlsignal.cpp added the #include <bb/data/DataSource>The below qml file =======

===============

import bb.cascades 1.0
import bb.data 1.0

Page {
content: ListView {
id: myListView
dataModel: dataModel
listItemComponents: [
ListItemComponent {
type: "item"
StandardListItem {
title: ListItemData.firstname + " " + ListItemData.lastname
description: ListItemData.title
}
}
]
//...
}
attachedObjects: [
GroupDataModel {
id: dataModel
},
DataSource {
id: dataSource
source: "asset:///sql/contacts.sql"
query: "select * from contact order by firstname, lastname"
onDataLoaded: {
dataModel.insertList(data);
}
}
]
onCreationCompleted: { dataSource.load(); }
}

==============

 

Thanks & Regards,

Venkatesan.R

Developer
Posts: 1,008
Registered: ‎12-12-2010
My Device: Passport (Red Limited Edition)
My Carrier: Mobile Vikings

Re: Database Connections.

Any useful console output? Also please use the 'Insert code' button next time, gives a much more readable result.

-------------------------------------------
BlackBerry Certified Builder for Native Application Development -- Proud member of the Belgian BlackBerry Developer group
Samples: Park in Ghent
Feeling generous? Nominate me for BB Elite member!
Developer
Posts: 124
Registered: ‎01-29-2011
My Device: Z10, PlayBook
My Carrier: Koodo

Re: Database Connections.

ventkasys, maybe I missed it, but I didn't see you comment on BBSJdev's note on the difference between MySQL and SQLite. Are you using SQLite?


BBSJdev wrote:

... 

There are differences in formats between MySql and SQlite ...