0

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..

Rohita Khatiwada
  • 2,835
  • 9
  • 40
  • 52

2 Answers2

1
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
) ;
SL5net
  • 2,282
  • 4
  • 28
  • 44
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.

Gary Hughes
  • 4,400
  • 1
  • 26
  • 40
  • Yeah, You are right about the space, and it was the cause of problem in my case. The solution you will provide will save value as %MyName% %myTel% in the table. Because when it sees the quote, it treats it as string value. – Rohita Khatiwada Jun 10 '11 at 13:12
  • 1
    I'm not sure what you mean. The line I posted will create a string with %MyName% and %myTel% replaced with their values. After assigning %MyName% and %myTel% values in a test script and adding 'MsgBox %$sSQL%' I see a valid query. – Gary Hughes Jun 10 '11 at 13:48