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 Contributor
Posts: 7
Registered: ‎12-05-2013
My Device: Z10
My Carrier: Yoigo

insert QString to Sqlite encoding

I've been developing for BB10 since last year, but I'm new in this forum so hi to everyone!

 

I have a problem saving data to Sqlite. I read a xml feed encoding in utf-8 with portuguese characters, I show all strings ok but when I insert them into database encoding fails. Here is my code:

 

once I haver received xml

void updater(QVariantMap responseData) {
    …
    …
    QVariantList championshipsList = responseData["Campeonato"].toList();
    for(int i = 0; i<championshipsList.length(); i++) {
        QVariantMap auxChampionship = championshipsList.at(i).toMap();
        Championship championship;
        championship.id = auxChampionship["Id"].toString().trimmed();
        championship.name = auxChampionship["Nome"].toString().trimmed();
        //at this point, name show right! ex: "Seleção Brasileira"
debug("Championship ID:"+championship.id+" Name:"+championship.name); if(!_databaseManager->existsChampionship(championship)) _databaseManager->insertChampionship(championship); else _databaseManager->updateChampionship(championship); } }

 

and insert/update database:

bool DataBaseManager::updateChampionship(Championship championship) {
    QString query("UPDATE championships SET 'name' = :name WHERE id = :id;");
 
    QVariantList l;
    l << championship.name << championship.id;
        DataAccessReply reply = _sqlconnection->executeAndWait(query, l);
 
        if (reply.hasError()) {
            gerror(QString("SQL Error: %1").arg(reply.errorMessage()));
            gerror("Query: " + query);
            return false;
        } else {
//SqlConnection *_sqlconnection in .hpp _sqlconnection->endTransaction(reply.id()); //info("Championship " + championship.name + "-" + championship.name + " inserted into database."); } return true; }

 

all data stored in database have wrong encoding (like "Seleção Brasileira"). 

I don't know what happen, because if I put "name" by constant string like:

 

championship.name = QString::fromUtf8("Seleção Brasileira");

 it works fine!

 

anyone knows how to fix it?

 

Thanks!!

 

Developer
Posts: 16,987
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: insert QString to Sqlite encoding

welcome to the support forums.

i would suggest that you try QSqlQuery to insert it, just to see if it works.
Maybe there is an encoding bug in sqconnection.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
New Contributor
Posts: 7
Registered: ‎12-05-2013
My Device: Z10
My Carrier: Yoigo

Re: insert QString to Sqlite encoding

Hi simon_hain!

ok, I will try it

I'll tell you in a minute...
New Contributor
Posts: 7
Registered: ‎12-05-2013
My Device: Z10
My Carrier: Yoigo

Re: insert QString to Sqlite encoding

Hi again,

 

I've tried this

 

bool DataBaseManager::updateChampionship(Championship championship) {
    QString querystring("UPDATE championships SET 'name' = :name WHERE id = :id;");

    QSqlDatabase _database = QSqlDatabase::addDatabase("QSQLITE");
    _database.setDatabaseName(QDir::homePath() + "/db/data.file");

    if(!_database.open()){
	return false;
    }

    QSqlQuery query(_database);
    query.prepare(querystring);
    query.bindValue(":id", championship.id);
    query.bindValue(":name", championship.name);
    bool success = query.exec();

    if (success) {
        gerror("SQL Error Query: " + querystring);
	return false;
    } 
    else {
	//info("Championship " + championship.name + "-" + championship.name + " inserted into database.");
    }

    return success;
}

 

but same error Smiley Sad

Developer
Posts: 1,746
Registered: ‎04-08-2010
My Device: Passport Silver, PRIV
My Carrier: Telekom.de, O2, Vodafone

Re: insert QString to Sqlite encoding

try SqlDataAccess

 

just did something with it and had no problems with umlauts

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

BlackBerry Elite Developer
BlackBerry Platinum Enterprise Partner
International Development native Mobile Business Apps
BlackBerry 10 | Qt Mobile (Android, iOS)
Workshops / Trainings / Bootcamps

blog: http://ekkes-corner.org
mobile-development: http://appbus.org Twitter: @ekkescorner
New Contributor
Posts: 5
Registered: ‎12-05-2013
My Device: Blackberry Z30
My Carrier: Bell Canada

Re: insert QString to Sqlite encoding

Dude! I think a saw a similar question in the SQLite3 users group. The OP was asking about SQLite3 locale compatabilty with his/her machine.  I suggest to try that group as well, they just might have the answer. Best wishes

Developer
Posts: 16,987
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: insert QString to Sqlite encoding

I have added a field with "Seleção Brasileira" to my sql database without any issues.
I don't use a property to retrieve the value though:

 

insertFolderQuery.bindValue(":displayName", folder->getDisplayName());

 I can see the correct value in SQLiteManager and retrieve it to display it without issues.

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
New Contributor
Posts: 7
Registered: ‎12-05-2013
My Device: Z10
My Carrier: Yoigo

Re: insert QString to Sqlite encoding

[ Edited ]

Hi simon_hain,

 

there is no problem if I try with const string as you say:

championship.name = QString::fromUtf8("Seleção Brasileira");

 

but if I try it with data read from web:

 

QVariantMap auxChampionship = championshipsList.at(i).toMap();
QString name = auxChampionship["Nome"].toString().trimmed();
championship.name = name;

 

 

insertion of this name into sql have encoding  problems.

Highlighted
New Contributor
Posts: 7
Registered: ‎12-05-2013
My Device: Z10
My Carrier: Yoigo

Re: insert QString to Sqlite encoding

do you know where to find this question? I can't find it Smiley Sad
thanks!!
Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: insert QString to Sqlite encoding

What question are you talking about, this thread?

 

If you have accessed this thread from your bio then it's in the Native Development forum.


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.