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
New Developer
Posts: 17
Registered: ‎05-22-2013
My Device: BB Z10
My Carrier: Tre in sweden

using same QML datamodel with SQL database in 2 listviews

I have the same problem using same QML datamodel with SQL database in 2 listviews .

 

I have also have the Quotes as my base and are making a tabview

 

I have soled the error

Warning: QSqlDatabasePrivate::removeDatabase: connection 'connect' is still in use, all queries will cease to work.
Warning: QSqlDatabasePrivate::addDatabase: duplicate connection name 'connect', old connection removed

 

with adding a new name. Will the make a new connection and what would the preferedway be?

//mSqlConnector = new SqlConnection(mSourceInDataFolder, "connect");

mSqlConnector = newSqlConnection(mSourceInDataFolder, name); 

 

I also have this in both my qml files (except that in the event names are named person.), would it be betterto have these on one qml fike?

CustomSqlDataSource{

 

id: asynkDataSource

 

source: "sql/teammanager.db"query: "SELECT * FROM events ORDER BY name LIMIT 10"propertyintloadCounter: 0

 

onDataLoaded: {

 

if(data.length > 10) {

eventsModel.

insertList(data);

 

// Load the next batch, the last parameter is set to zero to tell the data source that we are loading data to the list.var offsetData = {"offset": (10 + 5 * loadCounter)};

 

execute("eventconnect", "SELECT * FROM events ORDER BY name LIMIT 5 OFFSET Smiley Surprisedffset", offsetData, 0);

loadCounter ++;

}

}

}

New Developer
Posts: 17
Registered: ‎05-22-2013
My Device: BB Z10
My Carrier: Tre in sweden

Re: using same QML datamodel with SQL database in 2 listviews

Any thoughts?

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

Re: using same QML datamodel with SQL database in 2 listviews

So in total you have six database connections? One in C++ and two in QML for each file?


Please try formatting your code properly, it is near unreadable.

-------------------------------------------
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!
New Developer
Posts: 17
Registered: ‎05-22-2013
My Device: BB Z10
My Carrier: Tre in sweden

Re: using same QML datamodel with SQL database in 2 listviews

sorry. No two (I beleve)

 

in the two qml files I have. This are the PersonListPage.qml

attachedObjects: [
    // See PersonsModel.qml for set up of the GroupDataModel
    PersonsModel {
        id: personsModel
        onUpdateSelectedData: {
            if (indexPath[0] >= 0 && indexPath[1] >= 0) {
                //personsList.scrollToItem(indexPath, ScrollAnimation.Default);
                personsListPage.selectedData = data(indexPath);
            } else {
                personsListPage.listEmpty();
            }
        }
    }
,
    // Custom data source object, loads data using a SqlConnection, see customsqldatasource.cpp
    CustomSqlDataSource {
        id: asynkDataSource
        source: "sql/teammanager.db"
        //query: "SELECT * FROM persons ORDER BY lastname LIMIT 10"
        query: "SELECT * FROM persons ORDER BY lastname"
        property int loadCounter: 0
                    
        onDataLoaded: {
            if (data.length > 0) {
                personsModel.clear()
                personsModel.insertList(data);
                // Load the next batch, the last parameter is set to zero to tell 
                // the data source that we are loading data to the list.
                var offsetData = {"offset": (10 + 5 * loadCounter)};
                //execute("personconnect", "SELECT * FROM persons ORDER BY lastname LIMIT 5 OFFSET :offset", offsetData, 0);
                execute("personconnect", "SELECT * FROM persons ORDER BY lastname", offsetData, 0)
                loadCounter ++;
            }
        }
    }
] // attachedObjects

 And the other qml file (EventListPage.qml)

attachedObjects: [
    // See EventsModel.qml for set up of the GroupDataModel
    EventsModel {
        id: eventsModel
        onUpdateSelectedData: {
            if (indexPath[0] >= 0 && indexPath[1] >= 0) {
                //eventsList.scrollToItem(indexPath, ScrollAnimation.Default);
                eventsListPage.selectedData = data(indexPath);
            } else {
                eventsListPage.listEmpty();
            }
        }
    },
    // Custom data source object, loads data using a SqlConnection, see customsqldatasource.cpp
    CustomSqlDataSource {
        id: asynkDataSource
        source: "sql/teammanager.db"
        query: "SELECT * FROM events ORDER BY name LIMIT 10"
        property int loadCounter: 0
                    
        onDataLoaded: {
            if (data.length > 10) {
                eventsModel.insertList(data);
                // Load the next batch, the last parameter is set to zero to tell the data source
                // that we are loading data to the list.
                var offsetData = {"offset": (10 + 5 * loadCounter)};
                execute("eventconnect", "SELECT * FROM events ORDER BY name LIMIT 5 OFFSET :offset", offsetData, 0); 
                loadCounter ++;
            }
        }
    }
] // attachedObjects

 The cpp file has these.

void CustomSqlDataSource::execute (QString name, const QString& query, const QVariantMap &valuesByName, int id)
{
#ifdef DEBUG_MODE
	DebugMessage(QtDebugMsg, "CustomSqlDataSource : execute");
#endif

    if (checkConnection(name)) {
    		mSqlConnector->execute(query, valuesByName, id);
    }
}

 and

 

bool CustomSqlDataSource::checkConnection(QString name)
{
    if (mSqlConnector) {
        return true;
    } else {
        QFile newFile(mSourceInDataFolder);

        if (newFile.exists()) {
            // Remove the old connection if it exists
            if(mSqlConnector){
                disconnect(mSqlConnector, SIGNAL(reply(const bb::data::DataAccessReply&)), this,
                        SLOT(onLoadAsyncResultData(const bb::data::DataAccessReply&)));
                delete mSqlConnector;
            }

            // Set up a connection to the data base
            //mSqlConnector = new SqlConnection(mSourceInDataFolder, "connect");
            mSqlConnector = new SqlConnection(mSourceInDataFolder, name);

            // Connect to the reply function
            connect(mSqlConnector, SIGNAL(reply(const bb::data::DataAccessReply&)), this,
                    SLOT(onLoadAsyncResultData(const bb::data::DataAccessReply&)));

            return true;

        } else {
            qDebug() << "CustomSqlDataSource::checkConnection Failed to load data base, file does not exist.";
        }
    }
    return false;
}