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
Developer
Posts: 181
Registered: ‎07-19-2012
My Device: Q5, Q10, Z10, Z30, PlayBook
My Carrier: Carrier
Accepted Solution

SqlDataAccess was not declared in this scope

Learning how to use SQL in Cascades. 

 

I am following the sample provided in https://developer.blackberry.com/cascades/reference/bb__data__sqldataaccess.html

 

I have copied the sample code into my app.cpp and included the following two include statements:

#include <bb/cascades/GroupDataModel>
#include <bb/data/SqlDataAccess>

 Here is the code

 

// create a data model with sorting keys for firstname and lastname
GroupDataModel *model = 
  new GroupDataModel(QStringList() << "firstname" << "lastname");
 
// load the sql data from contacts table
SqlDataAccess sda("contacts.db");
QVariant list = sda.execute("select * from contact order by firstname");
 
// add the data to the model
model->insertList(list.value<QVariantList>());
 
// create a ListView control and add the model to the list
ListView *listView = new ListView();
listView->setDataModel(model);

 When I compile i get the following:

 

../src/app.cpp:21:5: error: 'SqlDataAccess' was not declared in this scope

 What am I doing wrong? 

 

Thanks!

---
If you find my post helpful please "like" it and "accept as a solution"
Developer
Posts: 181
Registered: ‎07-19-2012
My Device: Q5, Q10, Z10, Z30, PlayBook
My Carrier: Carrier

Re: SqlDataAccess was not declared in this scope

This thing is driving me crazy!!

 

Here is my app.cpp file:

 

#include "app.hpp"

#include <bb/cascades/Application>
#include <bb/cascades/QmlDocument>
#include <bb/cascades/AbstractPane>


#include <bb/data/DataAccess.hpp>
#include <bb/data/SqlConnection.hpp>
#include <bb/data/SqlDataAccess.hpp>


using namespace bb::cascades;

App::App()
{
    QmlDocument *qml = QmlDocument::create("main.qml");
    //-- setContextProperty expose C++ object in QML as an variable
    //-- uncomment next line to introduce 'this' object to QML name space as an 'app' variable
    //qml->setContextProperty("app", this);

    SqlDataAccess sda("contacts.db");

    AbstractPane *root = qml->createRootNode<AbstractPane>();
    Application::setScene(root);
}

 

and here is the error:

 

../src/app.cpp:22:5: error: 'SqlDataAccess' was not declared in this scope

 

What am I doing wrong??

---
If you find my post helpful please "like" it and "accept as a solution"
Developer
Developer
Posts: 44
Registered: ‎05-17-2012
My Device: Playbook, Dev Alpha A
My Carrier: O2

Re: SqlDataAccess was not declared in this scope

SqlDataAccess is in namespace bb::data.

 

Also you have to add the line:

 

LIBS += -lbbdata

 

to the *.pro file of your project. See here:

https://developer.blackberry.com/cascades/documentation/dev/upgrading/index.html#library

Developer
Posts: 181
Registered: ‎07-19-2012
My Device: Q5, Q10, Z10, Z30, PlayBook
My Carrier: Carrier

Re: SqlDataAccess was not declared in this scope

Thank you for your response, but I am completely new to C++ and struggling with this. 

 

I have added LIBS += -lbbdata to my .pro file and also tried adding:

 

#include <bb/data>

 

and

 

using namespace bb:data;

 

to the top of my app.cpp file without any luck.


Can you let me know what exactly i need to do in my code to get 

 

SqlDataAccess da("Contacts.db");

 

to work?

---
If you find my post helpful please "like" it and "accept as a solution"
Super Contributor
Posts: 306
Registered: ‎08-10-2010
My Device: Not Specified

Re: SqlDataAccess was not declared in this scope

Hi, SqlDataAccess is very simple on cascade. You can find sample from this link. In this WeatherGuesser is the application where SqlDataAccess is used Link: https://developer.blackberry.com/cascades/sampleapps/
Developer
Posts: 181
Registered: ‎07-19-2012
My Device: Q5, Q10, Z10, Z30, PlayBook
My Carrier: Carrier

Re: SqlDataAccess was not declared in this scope


Meghasanghvi wrote:
Hi, SqlDataAccess is very simple on cascade. You can find sample from this link. In this WeatherGuesser is the application where SqlDataAccess is used Link: https://developer.blackberry.com/cascades/sampleapps/

I actually looked at the WeatherGuesser app and cannot find any declarations of SqlDataAccess in the code to see how it should be done properly.

---
If you find my post helpful please "like" it and "accept as a solution"
Highlighted
Developer
Posts: 181
Registered: ‎07-19-2012
My Device: Q5, Q10, Z10, Z30, PlayBook
My Carrier: Carrier

Re: SqlDataAccess was not declared in this scope

OK so it was a namespace issue I was just not using it properly.

 

Adding 

 

#include <bb/data/SqlDataAccess.hpp>

 and then using

 

bb::data::SqlDataAccess da("Contacts.db");

 solved the problem. Thanks!

---
If you find my post helpful please "like" it and "accept as a solution"
Developer
Developer
Posts: 20
Registered: ‎07-22-2013
My Device: Z10
My Carrier: T-Mobile

Re: SqlDataAccess was not declared in this scope

Thank you very much - I had the exact same problem with XmlDataAccess!