Results 1 to 3 of 3

Thread: QSqlQuery::prepare() - placeholder as table name

  1. #1
    Join Date
    Mar 2011
    Location
    PL
    Posts
    11
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QSqlQuery::prepare() - placeholder as table name

    Is there any way to use placeholder as table name in prepare()? Or any other way to put the table name into a query in a safe way? I'm writing a network communicator and I need to create tables for registered users, user name will be the part of table name for each user, so I have to make these names safe. Any ideas?

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QSqlQuery::prepare() - placeholder as table name

    Last time I did something like this the table name was simply the MD5 of the users username. Sure, this meant browsing the tables with a sql browser meant they came out gibberish, but since the database was dedicated to user table storage, that didn't matter (and most usernames didn't make any more sense than the MD5 either...). It also gives you the added advantage of that the generated hash is automatically a safe table name (eg. 'USER_5d4c49dc300f29f0d0e5a85c9e5c47d8')

  3. #3
    Join Date
    Mar 2011
    Location
    PL
    Posts
    11
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSqlQuery::prepare() - placeholder as table name

    That's a good idea, but I think I will use something like this
    Qt Code:
    1. tabName = "user_" + userName.toUtf8.toHex();
    To copy to clipboard, switch view to plain text mode 
    instead od MD5. It will be possible to read user name in sql browser

Similar Threads

  1. How to delete results of QSqlQuery from table ?
    By homerun4711 in forum Newbie
    Replies: 2
    Last Post: 14th February 2011, 22:50
  2. Oracle 11g1 prepare for Qt4.4
    By landonmkelsey in forum Installation and Deployment
    Replies: 0
    Last Post: 3rd December 2008, 20:26
  3. QSqlQuery prepare() bindValue() broken badly
    By RolandHughes in forum Qt Programming
    Replies: 4
    Last Post: 14th November 2008, 18:25
  4. query prepare with sql math
    By GuL in forum Newbie
    Replies: 19
    Last Post: 2nd September 2008, 21:41
  5. Database and QSqlQuery::prepare problem
    By fengtian.we in forum Qt Programming
    Replies: 1
    Last Post: 31st October 2007, 23:17

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.