PDA

View Full Version : Sqlite question


ianhull
08-21-2004, 05:39 AM
HI, I am trying to grasp this Sqlite plugin but just can get the hang of it.
All I need is a page with 1 button and upon clicking that button data will be entered into the database. can anyone please send me a sample so I can see how It's done?

Thanks.

csd214
08-21-2004, 10:45 AM
HI, I started my learning process like this:

Create a button, cut’n paste the code from Example 3 in the help file (SQLite-QueryToTable()). Play with that code. Change ‘dbname’ from “;memory:” to a file name. Visit www.sqlite.org. Search AMS forum for “SQLite”. You will find several useful links and advices. Download sqlitebrowser.exe; very handy in the learning process. Have a look at Yearbook.apz.

So far I have succeeded to create two db.tables – “Customer” and “Turnover” – from CSV files. “Customer” is some of my EXEs in Program Files and “Turnover” is DLLs found in my program folder and with connection to the “customers”. The file size is the sales amount! I am going to play with this database to understand the aspect of SELECT, UPDATE and so on. I don’t think it is good idea to publish this project as a “demo”; it is not “clean” enough. And I’m still learning...(have a look at my post “Wrong direction”).

Good luck!
:)

Intrigued
08-21-2004, 11:02 AM
I did much the same csd214 did.

Here is some code from a project I am working on now. This is one way of doing such.


-- Set variables for each Input Object on the page

company_name = Input.GetText("CompanyINP");
address = Input.GetText("AddressINP");
addresstwo = Input.GetText("Address2INP");
city = Input.GetText("CityINP");
state = Input.GetText("StateINP");
zip = Input.GetText("ZIPINP");
phone = Input.GetText("PhoneINP");
fax = Input.GetText("FAXINP");
email = Input.GetText("EmailINP");
auth_rep = Input.GetText("AuthRepINP");

-- Format the data that the user typed into the Input fields in a manner that will show best in the Paragraph Object

all_company_info = company_name.."\r\n"..address.."\r\n"..addresstwo.."\r\n"..city.."\r\n"..state.."\r\n"..zip.."\r\n"..phone.."\r\n"..fax.."\r\n"..email.."\r\n"..auth_rep;

Paragraph.SetText("Paragraph1", all_company_info);

---------------------------------------------------------------------------------------

-- Select all from the compinfodb database
-- Then as long as all of the Input objects are not blank continue on

tblRecords = SQLite.QueryToTable(compinfodb, "select * from CUSTOMERS");

count = 1;

if (company_name ~= "") and (address ~= "") and (addresstwo ~= "") and (city ~= "") and (state ~= "") and (zip ~= "") and (phone ~= "") and (fax ~= "") and (email ~= "") and (auth_rep ~= "") then

-- This is where the data is actually put into (or replaced) the database

SQLite.Query(compinfodb, "insert or replace into COMPINFO values("..count..", "..Enclose(company_name)..", "..Enclose(address)..", "..Enclose(addresstwo)..", "..Enclose(city)..", "..Enclose(state)..", "..Enclose(zip)..", "..Enclose(phone)..", "..Enclose(fax)..", "..Enclose(email)..", "..Enclose(auth_rep)..")");

Input.SetText("CompanyINP", "");
Input.SetText("AddressINP", "");
Input.SetText("Address2INP", "");
Input.SetText("CityINP", "");
Input.SetText("StateINP", "");
Input.SetText("ZIPINP", "");
Input.SetText("PhoneINP", "");
Input.SetText("FAXINP", "");
Input.SetText("EmailINP", "");
Input.SetText("AuthRepINP", "");

Page.SetFocus("CompanyINP");

Dialog.TimedMessage("Success!", "Company information updated in the database!", 2000, MB_ICONINFORMATION);


else

-- Else if any fields are missing data then the user must fill them in before data will be inserted into the database

Dialog.TimedMessage("Failure", "Some fields are missing information!", 2000, MB_ICONEXCLAMATION);
end


---------------------------------------------------------------------------------------