How to insert values into sqlite3 using autohotkey

心不动则不痛 提交于 2020-01-17 01:17:20

问题


My problem is I am unable to insert values into sqlite3 using autohot key.

My code is:

MyName := name
myTel := telphonenumber


$sSQL := "insert into myTable Values ('" %MyName% "', " %myTel% ");"

and I also tried with ,

$sSQL := "insert into myTable Values ( ' " . MyName . " ', " . myTel . ");"

But neither of these works.

Any suggestion is appreciated..


回答1:


I've not used AHK with SQLite before, but is it just the query you're having issues with? Try this (note the lack of the colon before the equals sign):

$sSQL = "insert into myTable Values ('%MyName%', '%myTel%');"

Your second attempt produces a query that is technically valid, but it would put a space either side of the name in the database ('John' would be ' John '). Also I'm guessing you don't really want to be using a numeric field in your database for a telephone number? If a number begins with 0 or is to large you could have issues. The version above will insert it as a string.




回答2:


MyName := name
myTel := telphonenumber

$sSQL := "insert into myTable Values ('" MyName "', '" myTel "');"

I prefer to put the phone number also into apostrophe. if you do not have a phone number then there is no error:

insert into myTable Values ('John', '' );

and as Gary said right: "If a number begins with 0 or ... issues." the select of the telephone number
0177... will give you later 177...

better you also use a string for the phone number and not an number format.

create table myTable
(
    name TEXT
    phone TEXT
) ;


来源:https://stackoverflow.com/questions/6294494/how-to-insert-values-into-sqlite3-using-autohotkey

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!