Run multiple commands in sqlite manager

后端 未结 3 1094
温柔的废话
温柔的废话 2020-12-21 08:15

It\'s possible to run more than one command in the direct SQL execution in SQlite Manager? (useful if you insert a lot of data)

e.g.

insert into Test         


        
相关标签:
3条回答
  • 2020-12-21 08:30

    Perhaps you may work executemany() method instead of execute()

    Something like:

    values = [
        ("Thomas", 25),
        ("Peter", 29)
    ]
    conn.executemany("insert into TestTable (Name, Age) values (?, ?)", values)
    

    Will work fine.

    0 讨论(0)
  • 2020-12-21 08:42

    Solution is very simple ;-)

    -> use a semicolon to separate the commands

    insert into TestTable (Name, Age) values("Thomas", 25);
    insert into TestTable (Name, Age) values("Peter", 29);
    ...
    
    0 讨论(0)
  • 2020-12-21 08:47

    Alternatively, you could write the statement as:

    insert into TestTable (Name, Age) 
    values
    ("Thomas", 25),
    ("Peter", 29)
    ;
    

    Edit: Please note, as per @DominiqueJacquel's comment, that this will only work in SQLite version 3.7.11+

    0 讨论(0)
提交回复
热议问题