Results 1 to 2 of 2

Thread: sql select with unicode

  1. #1
    Join Date
    May 2013
    Posts
    45
    Thanks
    11
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default sql select with unicode

    Hi.

    how can i select data from postgresql with unicode character?

    in sql admin work this two select:

    SELECT st_astext(way) FROM planet_osm_roads WHERE boundary='administrative' AND admin_level='2' AND name='საქართვ ელო';

    SELECT st_astext(way) FROM planet_osm_roads WHERE boundary='administrative' AND admin_level='2' AND name=U&'\10e1\10d0\10e5\10d0\10e0\10d7\10d5\10d4\1 0da\10dd';


    but when i try this select in my qt c++ program nothing send back


    sql database is in UTF8



    EDIT: this work:

    QString test= QString::fromUtf8 ("საქართვრ”ლო");
    query.prepare("SELECT st_astext(way) FROM planet_osm_roads WHERE boundary='administrative' AND admin_level='2' AND name='"+ test +"';");
    Last edited by stevocz; 18th June 2013 at 12:10.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: sql select with unicode

    Your first option will only work if you tell Qt it is UTF-8 encoded (assuming it is):
    Qt Code:
    1. QSqlQuery qry(QString::fromUtf8("SELECT st_astext(way) FROM planet_osm_roads WHERE boundary='administrative' AND admin_level='2' AND name='საქართველო' "));
    To copy to clipboard, switch view to plain text mode 
    Your second option will only work if you escape the backslashes correctly for a C++ string:
    Qt Code:
    1. QSqlQuery qry("SELECT st_astext(way) FROM planet_osm_roads WHERE boundary='administrative' AND admin_level='2' AND name=U&'\\10e1\\10d0\\10e5\\10d0\\10e0\\10d7\\10d5\\10d4\\10da\\10dd' ");
    To copy to clipboard, switch view to plain text mode 

    You should use query parameters rather than pasting string fragments together when building the SQL. This is especially important if the name comes from a user.

  3. The following user says thank you to ChrisW67 for this useful post:

    stevocz (19th June 2013)

Similar Threads

  1. Qt Unicode Problems
    By Sven in forum Qt Programming
    Replies: 9
    Last Post: 28th December 2010, 06:28
  2. [disable unicode]
    By tri407tiny in forum Newbie
    Replies: 3
    Last Post: 5th May 2010, 02:20
  3. Unicode
    By qtuser20 in forum Qt Programming
    Replies: 0
    Last Post: 28th September 2009, 21:43
  4. Printing Unicode?
    By auba in forum Qt Programming
    Replies: 2
    Last Post: 4th June 2009, 15:24
  5. i have a problem with Qt unicode
    By coder1985 in forum Qt Programming
    Replies: 5
    Last Post: 20th November 2007, 20:08

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.