Page 2 of 2 FirstFirst 12
Results 21 to 27 of 27

Thread: copying between MSSql and a SQLite database

  1. #21
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: copying between MSSql and a SQLite database

    That look almost like it should be done. Have you tried the code, because it works not like you would expect it. First move the query2.exec() inside the loop and you want to call commit() on db2!

  2. The following user says thank you to Lykurg for this useful post:

    sattu (8th February 2011)

  3. #22
    Join Date
    Sep 2010
    Location
    Bangalore
    Posts
    169
    Thanks
    59
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: copying between MSSql and a SQLite database

    Quote Originally Posted by Lykurg View Post
    That look almost like it should be done. Have you tried the code, because it works not like you would expect it. First move the query2.exec() inside the loop and you want to call commit() on db2!
    You mean this way:
    Qt Code:
    1. while(query.next())
    2. {
    3. id = query.record().value(0).toInt();
    4. name = query.record().value(1).toString();
    5. query2.bindValue(0, id);
    6. query2.bindValue(1, name);
    7. query2.exec();
    8. }
    9. ok = db.commit()
    To copy to clipboard, switch view to plain text mode 

    Actually you are right Lykurg. This is not exactly what i want as i have already done it this way. To be precise, i want to avoid the following lines:
    Qt Code:
    1. id = query.record().value(0).toInt();
    2. name = query.record().value(1).toString();
    To copy to clipboard, switch view to plain text mode 

    I donot want to manually extract from db and then put the values back in db2. I want the same thing to happen but only by the usage of queries.
    Is it possible? Somehow i want to avoid this extraction kind of thing.

  4. #23
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: copying between MSSql and a SQLite database

    Quote Originally Posted by sattu View Post
    I donot want to manually extract from db and then put the values back in db2. I want the same thing to happen but only by the usage of queries.
    Is it possible? Somehow i want to avoid this extraction kind of thing.
    You can't avoid that because you are using two different database systems. There is no such feature like
    sql Code:
    1. SELECT ... INTO
    To copy to clipboard, switch view to plain text mode 

  5. The following user says thank you to Lykurg for this useful post:

    sattu (8th February 2011)

  6. #24
    Join Date
    Sep 2010
    Location
    Bangalore
    Posts
    169
    Thanks
    59
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: copying between MSSql and a SQLite database

    Quote Originally Posted by Lykurg View Post
    You can't avoid that because you are using two different database systems. There is no such feature like
    sql Code:
    1. SELECT ... INTO
    To copy to clipboard, switch view to plain text mode 
    Ok, then it's completely fine. Thanks for helping me so much.
    So is my code o.k or i need to make any better modifications over it?

  7. #25
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: copying between MSSql and a SQLite database

    I think it is fine and if it works, perfect. You could skip the local variables in the while loop which will speed up things a little bit. (If the compiler doesn't do so already which he normaly should...)

  8. The following user says thank you to Lykurg for this useful post:

    sattu (8th February 2011)

  9. #26
    Join Date
    Sep 2010
    Location
    Bangalore
    Posts
    169
    Thanks
    59
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: copying between MSSql and a SQLite database

    Quote Originally Posted by Lykurg View Post
    I think it is fine and if it works, perfect. You could skip the local variables in the while loop which will speed up things a little bit. (If the compiler doesn't do so already which he normaly should...)
    Yaa yaa, i am able to do like that.
    Actually, i need to tell one more thing and hope it doesnot irritate you.
    As i told before, first we are doing for general PC to PC connection, if it is fine then we are putting it in our embedded board. This also i told previously the error that we are getting while we are trying from board. Board is not able to fetch the string or char type data,
    Qt Code:
    1. qGetStringData: Error while fetching data ( "[FreeTDS][SQL Server]Program type out of range" )
    To copy to clipboard, switch view to plain text mode 

    the solutions that tbscope had provided, i worked on both, but thats not working. I mean, i tried for qt4.6.3, there we are able to fetch string data, but some other issues are coming.
    So, now i want to know one thing. Currently i am using this query to fetch data:
    "select * from user20"
    Is there any other way or queries by which i can fetch basic character type variables from remote table?
    Also, our string variable is of maximum 10chars. And we are using varchar type. What other data types we can use for the same thing? (like nchar or nvarchar or something like that)
    Last edited by sattu; 8th February 2011 at 10:59. Reason: one more addition

  10. #27
    Join Date
    Jun 2016
    Posts
    99
    Thanks
    18
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: copying between MSSql and a SQLite database

    sattu,

    I know this is old but for any one else who might need this... This way use two database connections

    Copies rows from one database table that are older than 30 days and stores them in another database table for archiving and then deletes the rows.

    Qt Code:
    1. dbConnect();
    2. archiveDbConnect();
    3.  
    4. QSqlQuery archiveDataQry("SELECT * FROM userlogevents7", m_selectDataBase);
    5. QSqlQuery copyDataQry(m_archiveDataBase);
    6.  
    7. int id;
    8. QString userName;
    9. QString eventMessage;
    10. QDate dateTime;
    11.  
    12. if(archiveDataQry.exec()){
    13. qDebug()<<"sql statement exicuted fine";
    14. }
    15. else{
    16. qDebug() << "Errors accured with sql statement";
    17. qDebug() << archiveDataQry.lastError();
    18. }
    19.  
    20. m_selectDataBase.transaction();
    21.  
    22. if(copyDataQry.prepare("INSERT INTO usereventarchive (id, userName, eventMessage, dateTime) VALUES (:id, :userName, :eventMessage, :dateTime)"))
    23. {
    24. qDebug()<<"prepare sql statement exicuted fine";
    25. }
    26. else{
    27. qDebug() << "Errors accured with prepare sql statement";
    28. qDebug() << copyDataQry.lastError();
    29. }
    30.  
    31. while(archiveDataQry.next()){
    32. id = archiveDataQry.record().value(0).toInt();
    33. userName = archiveDataQry.record().value(1).toString();
    34. eventMessage = archiveDataQry.record().value(2).toString();
    35. dateTime = archiveDataQry.record().value(3).toDate();
    36. copyDataQry.bindValue(0,id);
    37. copyDataQry.bindValue(1, userName);
    38. copyDataQry.bindValue(2, eventMessage);
    39. copyDataQry.bindValue(3, dateTime);
    40. if(copyDataQry.exec()){
    41. qDebug()<<"copy sql statement exicuted fine";
    42. }
    43. else{
    44. qDebug() << "Errors accured with copy sql statement";
    45. qDebug() << copyDataQry.lastError();
    46. }
    47. }
    48. m_selectDataBase.commit();
    49. m_selectDataBase.close();
    50. }
    To copy to clipboard, switch view to plain text mode 

    hope this helps any one that may need it...

Similar Threads

  1. Replies: 6
    Last Post: 25th November 2010, 21:02
  2. Use QT to set password for SQLITE database. help...!
    By Kevin Hoang in forum Qt Programming
    Replies: 1
    Last Post: 11th March 2010, 07:28
  3. SQLITE ATTACH database
    By drescherjm in forum Qt Programming
    Replies: 8
    Last Post: 9th December 2009, 07:25
  4. SQLITE database problems
    By phoenix in forum Newbie
    Replies: 3
    Last Post: 30th April 2007, 21:38
  5. [QT4][SQLITE] Database and query
    By agent007se in forum Newbie
    Replies: 10
    Last Post: 12th July 2006, 22:16

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.