Syntax SQLITE 2 tables not working



  • Hello, following SQLite tutorial, I can use 2 tables and add conditions but the condition is not accepted, why?
    here the syntax is accepted and it working without condition:

    function dbregistration()
    {
        var db = dbGetHandle()
        db.transaction(function (tx) {
            var results = tx.executeSql(
    'SELECT  * FROM table1_log,table2_log where table1_log.registration=table2_log.registration')
    

    but with the condition to filter for each registration I got message:
    Error: ambiguous column name: registration

    function dbregistration(Pregistration)
    {
        var db = dbGetHandle()
        db.transaction(function (tx) {
            var results = tx.executeSql(
    'SELECT  * FROM table1_log,table2_log where table1_log.registration=table2_log.registration and registration=?'[Pregistration])
    

    Thank you for your help ;-)


  • Moderators

    @filipdns

    What programming language are you using?
    Where is the relation to Qt?

    @filipdns said in syntax SQLITE 2 tables not working in QT, why?:

    function dbregistration(Pregistration)
    {
        var db = dbGetHandle()
        db.transaction(function (tx) {
            var results = tx.executeSql(
    'SELECT  * FROM table1_log,table2_log where table1_log.registration=table2_log.registration and registration=?'[Pregistration])
    

    This syntax looks like using an array. But using an index for a constant string does not make sense.



  • In first I'm using qml and JS for queries.

    What I want to do is :
    2 tables,
    table2 had only 1 row for each registration.
    when new entry is done in table1, a value of column2 of table1 increase a value of column3 of table2 (table1.column2 + table2.column3=new value of table2.column3)
    the common column of both tables is registration
    but in tableview qml, I want to show only values of one registration following data (Pregistration) from stackview .

    the relation with QT and *.js is just I supposed I have do make other syntax than SQLite page say because I found tutorial with the "word" AND + conditions but I'm unable to make it working.

    here what I found on SQLite page:

    
    SELECT CLI_NAME, MOB_NUMBER
    FROM T_CUSTOMER C, T_PHONE T
    WHERE C.CLI_ID = T.CLI_ID
      AND TYP_CODE = 'FAX'
    

  • Moderators

    @filipdns

    I am not a QSQL expert, but to my understanding all SQL key words shall be in capital. Also basically it is part of the SQL driver to translate the commands and to execute. Therefore, you need pay attention to the respective syntax of the driver you are using.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.