No data in sqlite datbase after insert statement.
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
- Posts: 108
- Joined: Mon Mar 20, 2017 5:13 am
No data in sqlite datbase after insert statement.
Hello, I'm able to insert data into my database, but when I go to check it through the sqlite manager on Firefox I cannot see any data. Yet when I run my insert statement through the execute sql tab it shows up in the table.
Small portion of my problem:
-- This is in the stack script.
on preOpenStack
global gConnectionID
put specialFolderPath("desktop" & "/FIRST.sqlite") into tDatabaseAddress
put revOpenDatabase("sqlite", tDatabaseAddress) into gConnectionID
end preOpenStack
-- This is the script of a button.
on mouseUp
put the text of field "field_UserName_NewAccount" into tUserName
put the text of field "field_Password_NewAccount" into tPassword
put the text of field "field_ConfirmPassword_NewAccount" into tConfirmPassword
put "INSERT INTO MentorAccount VALUES ('tUserName','tPassword','tConfirmPassword');" into tSQL
revExecuteSQL, gConnectionID, tSQL
revCloseDatabase gConnectionID
end mouseUp
To conclude the insert statement works fine in sqlite manager but no data is actually inserted into the database.
Small portion of my problem:
-- This is in the stack script.
on preOpenStack
global gConnectionID
put specialFolderPath("desktop" & "/FIRST.sqlite") into tDatabaseAddress
put revOpenDatabase("sqlite", tDatabaseAddress) into gConnectionID
end preOpenStack
-- This is the script of a button.
on mouseUp
put the text of field "field_UserName_NewAccount" into tUserName
put the text of field "field_Password_NewAccount" into tPassword
put the text of field "field_ConfirmPassword_NewAccount" into tConfirmPassword
put "INSERT INTO MentorAccount VALUES ('tUserName','tPassword','tConfirmPassword');" into tSQL
revExecuteSQL, gConnectionID, tSQL
revCloseDatabase gConnectionID
end mouseUp
To conclude the insert statement works fine in sqlite manager but no data is actually inserted into the database.
Re: No data in sqlite datbase after insert statement.
Hi,
Else you should always do this:This will tell you in time when a query fails, often including the reason.
Further:
Have fun!
*1): Don't say "Axwald, you moron, do you think I'm stupid?" - I don't know how often I fooled myself forgetting this ...
You do a refresh in SQLite Manager after the insert (Shift-F5)? *1)Quinton B. wrote:Hello, I'm able to insert data into my database, but when I go to check it through the sqlite manager on Firefox I cannot see any data. Yet when I run my insert statement through the execute sql tab it shows up in the table.
Else you should always do this:
Code: Select all
...
revExecuteSQL, gConnectionID, tSQL
if the result is not a number then
answer error "Ooops:" & CR & the result
end if
...
Further:
Noooo! At least use:Quinton B. wrote:Code: Select all
put the text of field "field_Password_NewAccount" into tPassword
Code: Select all
put SHAencode(the text of field "field_Password_NewAccount") into tPassword
function SHAencode MyString
get sha1digest(MyString)
put empty into MyVar
get binarydecode("H*",it,MyVar)
return myvar
end SHAencode
*1): Don't say "Axwald, you moron, do you think I'm stupid?" - I don't know how often I fooled myself forgetting this ...
All code published by me here was created with Community Editions of LC (thus is GPLv3).
If you use it in closed source projects, or for the Apple AppStore, or with XCode
you'll violate some license terms - read your relevant EULAs & Licenses!
If you use it in closed source projects, or for the Apple AppStore, or with XCode
you'll violate some license terms - read your relevant EULAs & Licenses!
Re: No data in sqlite datbase after insert statement.
This is an error, correct code is code:Quinton B. wrote:Hello, I'm able to insert data into my database, but when I go to check it through the sqlite manager on Firefox I cannot see any data. Yet when I run my insert statement through the execute sql tab it shows up in the table.
Small portion of my problem:
Code: Select all
-- This is in the stack script. on preOpenStack global gConnectionID put specialFolderPath("desktop" & "/FIRST.sqlite") into tDatabaseAddress
Code: Select all
put (specialFolderPath("desktop") & "/FIRST.sqlite") into tDatabaseAddress
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
-
- Posts: 108
- Joined: Mon Mar 20, 2017 5:13 am
Re: No data in sqlite datbase after insert statement.
I have already tried refreshing the database earlier and it doesn't do anything.
Re: No data in sqlite datbase after insert statement.
Every handler that uses a global variable must declare the global. The preopenstack handler does that but the button mouseUp does not. That means that the button doesn't know what gConnectionID is, and the command will not run correctly.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
-
- Posts: 108
- Joined: Mon Mar 20, 2017 5:13 am
Re: No data in sqlite datbase after insert statement.
Actually, it was, I just forgot to put that in my first question, because I was typing it from my phone, but here is all the code from my mac.
--------------------------------------------------
global gConnectionID
on mouseUp
-- check the global connection ID to make sure we have a database connection
if gConnectionID is not a number then
answer error "Please connect to the database first."
exit to top
end if
-- edit these variables to match your database & table
-- this assumes a table called Table1 with 3 fields
put the text of field "field_UserName_NewAccount" into
put SHAencode(the text of field "field_Password_NewAccount") into tPassword
put the text of field "field_ConfirmPassword_NewAccount" into tConfirmPassword
put tConfirmPassword into tCP
put the text of field "field_TeamNumber_NewAccount" into tTeamNumber
put tTeamNumber into tTN
put the text of field "field_Email_NewAccount" into tEmail
put tEmail into tE
put the text of field "field_ConfirmEmail_NewAccount" into tConfirmEmail
put tConfirmEmail into tCE
put the text of field "field_PhoneNumber_NewAccount" into tPhoneNumber
put tPhoneNumber into tPN
put the text of field "field_ConfirmPhoneNumber_NewAccount" into tConfirmPhoneNumber
put tConfirmPhoneNumber into tCPN
put the text of button "button_Country_NewAccount" into tCountry
put tCountry into tC
put the text of field "field_Street_NewAccount" into tStreet
put tStreet into tS
put the text of field "field_State_NewAccount" into tState
put tState into tST
put the text of field "field_City_NewAccount" into tCity
put tCity into tCI
put the text of field "field_ZipCode_NewAccount" into tZipCode
put tZipCode into tZC
put the text of field "field_StateIdNumber_NewAccount" into tSateIdNumber
put tStateIdNumber into tSIN
put the text of field "field_FirstName_NewAccount" into tFirstName
put tFirstName into tFN
put the text of field "field_MiddleName_NewAccount" into tMiddleName
put tMiddleName into tMN
put the text of field "field_LastName_NewAccount" into tLastName
put tLastName into tLN
put the text of field "field_Age_NewAccount" into tAge
put tAge into tA
put the text of field "field_TIMSNumber_NewAccount" into tTIMSNumber
put tTIMSNumber into tTIMSN
put the text of button "button_SecurityQuestion_NewAccount" into tSecurityQuestion
put tSecurityQuestion into tSQ
put the text of field "field_SecurityQuestion_NewAccount" into tSecurityQuestionAnswer
put tSecurityQuestionAnswer into tSQA
-- Table Name
-- construct the SQL - the :1, :2 & :3 placeholders in the SQL will be filled by variables in the revExecuteSQL line
//put tUN, tP, tCP, tTN, tE, tCE, tPN, tCPN, tC, tS, tST, tCI, tZC, tSIN, tFN, tMN, tLN, tA, tTIMSN, tSQ, tSQA into tValues
put "INSERT INTO MentorAccount VALUES ('tUserName','tPassword','tCP','tTN','tE','tCE','tPN','tCPN','tC','tS','tST','tCI','tZC','tSIN','tFN','tMN','tLN','tA','tTIMSN','tSQ','tSQA');" into tSQL
-----(UserName,Password,ConfirmPassword,TeamNumber,Email,ConfirmEmail,PhoneNumber,ConfirmPhoneNumber,Country,Street,State,City,ZipCode,StateIdNumber,FirstName,MiddleName,LastName,Age,TIMSNumber,SecurityQuestion,SecurityQuestionAnswer)
/*put "INSERT INTO MentorAccount (UserName,Password,ConfirmPassword,TeamNumber,Email,CoqnfirmEmail,PhoneNumber,ConfirmPhoneNumber,Country,Street,State,City,ZipCode,StateIdNumber,FirstName,MiddleName,LastName,Age,TIMSNumber,SecurityQuestion,SecurityQuestionAnswer) " & \
merge("VALUES ('[[tUN]]', '[[tP]]', '[[tCP]]', '[[tTN]]', '[[tE]]', '[[tCE]]', '[[tPN]]', '[[tCPN]]', '[[tC]]', '[[tS]]', '[[tST]]', '[[tCI]]', '[[tZC]]', '[[tSIN]]', '[[tFN]]', '[[tMN]]', '[[tLN]]', '[[tA]]', '[[tTIMSN]]', '[[tSQ]]', '[[tSQA]]')") into tSQL*/
-- send the SQL to the database, filling in the placeholders with data from variables
revExecuteSQL gConnectionID, tSQL -- check the result and display the data or an error message
if tSQL is not empty then
answer info "New record added."
else
answer error "There was a problem adding the record to the database:" & cr & the result
end if
revCloseDatabase gConnectionID
end mouseUp
-------------------------------------------------
function SHAencode MyString
get sha1digest(MyString)
put empty into MyVar
get binarydecode("H*",it,MyVar)
return myvar
end SHAencode
--------------------------------------------------
global gConnectionID
on mouseUp
-- check the global connection ID to make sure we have a database connection
if gConnectionID is not a number then
answer error "Please connect to the database first."
exit to top
end if
-- edit these variables to match your database & table
-- this assumes a table called Table1 with 3 fields
put the text of field "field_UserName_NewAccount" into
put SHAencode(the text of field "field_Password_NewAccount") into tPassword
put the text of field "field_ConfirmPassword_NewAccount" into tConfirmPassword
put tConfirmPassword into tCP
put the text of field "field_TeamNumber_NewAccount" into tTeamNumber
put tTeamNumber into tTN
put the text of field "field_Email_NewAccount" into tEmail
put tEmail into tE
put the text of field "field_ConfirmEmail_NewAccount" into tConfirmEmail
put tConfirmEmail into tCE
put the text of field "field_PhoneNumber_NewAccount" into tPhoneNumber
put tPhoneNumber into tPN
put the text of field "field_ConfirmPhoneNumber_NewAccount" into tConfirmPhoneNumber
put tConfirmPhoneNumber into tCPN
put the text of button "button_Country_NewAccount" into tCountry
put tCountry into tC
put the text of field "field_Street_NewAccount" into tStreet
put tStreet into tS
put the text of field "field_State_NewAccount" into tState
put tState into tST
put the text of field "field_City_NewAccount" into tCity
put tCity into tCI
put the text of field "field_ZipCode_NewAccount" into tZipCode
put tZipCode into tZC
put the text of field "field_StateIdNumber_NewAccount" into tSateIdNumber
put tStateIdNumber into tSIN
put the text of field "field_FirstName_NewAccount" into tFirstName
put tFirstName into tFN
put the text of field "field_MiddleName_NewAccount" into tMiddleName
put tMiddleName into tMN
put the text of field "field_LastName_NewAccount" into tLastName
put tLastName into tLN
put the text of field "field_Age_NewAccount" into tAge
put tAge into tA
put the text of field "field_TIMSNumber_NewAccount" into tTIMSNumber
put tTIMSNumber into tTIMSN
put the text of button "button_SecurityQuestion_NewAccount" into tSecurityQuestion
put tSecurityQuestion into tSQ
put the text of field "field_SecurityQuestion_NewAccount" into tSecurityQuestionAnswer
put tSecurityQuestionAnswer into tSQA
-- Table Name
-- construct the SQL - the :1, :2 & :3 placeholders in the SQL will be filled by variables in the revExecuteSQL line
//put tUN, tP, tCP, tTN, tE, tCE, tPN, tCPN, tC, tS, tST, tCI, tZC, tSIN, tFN, tMN, tLN, tA, tTIMSN, tSQ, tSQA into tValues
put "INSERT INTO MentorAccount VALUES ('tUserName','tPassword','tCP','tTN','tE','tCE','tPN','tCPN','tC','tS','tST','tCI','tZC','tSIN','tFN','tMN','tLN','tA','tTIMSN','tSQ','tSQA');" into tSQL
-----(UserName,Password,ConfirmPassword,TeamNumber,Email,ConfirmEmail,PhoneNumber,ConfirmPhoneNumber,Country,Street,State,City,ZipCode,StateIdNumber,FirstName,MiddleName,LastName,Age,TIMSNumber,SecurityQuestion,SecurityQuestionAnswer)
/*put "INSERT INTO MentorAccount (UserName,Password,ConfirmPassword,TeamNumber,Email,CoqnfirmEmail,PhoneNumber,ConfirmPhoneNumber,Country,Street,State,City,ZipCode,StateIdNumber,FirstName,MiddleName,LastName,Age,TIMSNumber,SecurityQuestion,SecurityQuestionAnswer) " & \
merge("VALUES ('[[tUN]]', '[[tP]]', '[[tCP]]', '[[tTN]]', '[[tE]]', '[[tCE]]', '[[tPN]]', '[[tCPN]]', '[[tC]]', '[[tS]]', '[[tST]]', '[[tCI]]', '[[tZC]]', '[[tSIN]]', '[[tFN]]', '[[tMN]]', '[[tLN]]', '[[tA]]', '[[tTIMSN]]', '[[tSQ]]', '[[tSQA]]')") into tSQL*/
-- send the SQL to the database, filling in the placeholders with data from variables
revExecuteSQL gConnectionID, tSQL -- check the result and display the data or an error message
if tSQL is not empty then
answer info "New record added."
else
answer error "There was a problem adding the record to the database:" & cr & the result
end if
revCloseDatabase gConnectionID
end mouseUp
-------------------------------------------------
function SHAencode MyString
get sha1digest(MyString)
put empty into MyVar
get binarydecode("H*",it,MyVar)
return myvar
end SHAencode
Re: No data in sqlite datbase after insert statement.
Hi,
So try this:
This way you'll get a warning if it fails, and have any useful error data ready to paste here ;-) Try it, and let us know what happened!
Have fun!
Beside possible other quirks you don't check the result. tSQL should contain the SQL string (that would be useful see to determine if it's correct), but what comes back from the query is in "the result"!Quinton B. wrote:Code: Select all
revExecuteSQL gConnectionID, tSQL -- check the result and display the data or an error message if tSQL is not empty then answer info "New record added." else answer error "There was a problem adding the record to the database:" & cr & the result end if
So try this:
Code: Select all
...
revExecuteSQL, gConnectionID, tSQL
if the result is not a number then -- the result is a number, or an error description
put the result & CR & gConnectionID & CR & tSQL into myErr -- we construct a variable
set the clipboardData["text"] to myErr -- and copy it for further pasting
answer error "Ooops:" & CR & myErr -- and thow an error
end if
...
Have fun!
All code published by me here was created with Community Editions of LC (thus is GPLv3).
If you use it in closed source projects, or for the Apple AppStore, or with XCode
you'll violate some license terms - read your relevant EULAs & Licenses!
If you use it in closed source projects, or for the Apple AppStore, or with XCode
you'll violate some license terms - read your relevant EULAs & Licenses!
Re: No data in sqlite datbase after insert statement.
into ???put the text of field "field_UserName_NewAccount" into
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
Re: No data in sqlite datbase after insert statement.
However use:
########CODE to copy and paste#######
put revDataFromQuery(tab,return,gConnectionID,tSQL) into tRecords
if tRecords is not empty then
answer info "New record added."
else
answer error "There was a problem adding the record to the database:" & cr & the tRecords
end if
#####END OF CODE generated by http://tinyurl.com/j8xf3xq with livecode 9.0.0-dp-6#####
########CODE to copy and paste#######
put revDataFromQuery(tab,return,gConnectionID,tSQL) into tRecords
if tRecords is not empty then
answer info "New record added."
else
answer error "There was a problem adding the record to the database:" & cr & the tRecords
end if
#####END OF CODE generated by http://tinyurl.com/j8xf3xq with livecode 9.0.0-dp-6#####
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
-
- Posts: 108
- Joined: Mon Mar 20, 2017 5:13 am
Re: No data in sqlite datbase after insert statement.
Thanks, Guys, I figured it out.
Here is the correct statement.
revExecuteSQL gDatabaseID, "INSERT INTO MentorAccount VALUES (:1,:2,:3, :4, :5, :6, :7, :8, :9, :10, :11, :12, :13, :14, :15, :16, :17, :18, :19, :20, :21)","tUserName","tPassword","tConfirmPassword","tTeamNumber","tEmail","tConfirmEmail","tPhoneNumber","tConfirmPhoneNumber","tCountry","tStreet","tState","tCity","tZipCode","tStateIdNumber","tFirstName","tMiddleName","tLastName","tAge","tTIMSNumber","tSecurityQuestion","tSecurityQuestionAnswer"
Here is the correct statement.
revExecuteSQL gDatabaseID, "INSERT INTO MentorAccount VALUES (:1,:2,:3, :4, :5, :6, :7, :8, :9, :10, :11, :12, :13, :14, :15, :16, :17, :18, :19, :20, :21)","tUserName","tPassword","tConfirmPassword","tTeamNumber","tEmail","tConfirmEmail","tPhoneNumber","tConfirmPhoneNumber","tCountry","tStreet","tState","tCity","tZipCode","tStateIdNumber","tFirstName","tMiddleName","tLastName","tAge","tTIMSNumber","tSecurityQuestion","tSecurityQuestionAnswer"