PDA

View Full Version : SQLite - HOW-TO: Populate via file's data


Intrigued
08-30-2006, 07:16 PM
-- Will open, if it exists, or create a new database and put it on the Desktop
db = SQLite.Open(_DesktopFolder.."\\a_database.db")

-- Add in the table's fields (Column headings)
SQLite.Query(db,"create table COMPANY(ID integer primary key, Company text, Address text, Phone text, Due integer)");

-- Takes the file's data and puts it into an AMS table format
tblRecs = TextFile.ReadToTable("AutoPlay\\Docs\\a_text_file.txt")

--[[
Finally, each item the previously made table has is added to the database

Note: When you add in the data it has to be in the order in which the
Column headings were added into the database (ie. ID, Company, Address, Phone, Due in this example)
Thus we are only adding in data to the second (2nd) position which is the Company name (where the 'v' is)
]]
for i,v in tblRecs do
SQLite.Query(db,"insert into COMPANY values(NULL,".."'"..v.."'".."'','','','')");
end

ps. I kept this code short so that it would be easy to understand, but each time you Query to the database, you should check for errors.

err = Application.GetLastError();
if err = SQLite.ERROR then
strErrMsg = SQLite.GetLastErrorString();
Debug.Print("Error: " .. strErrMsg);
end

azmanar
09-01-2006, 02:29 PM
Hi Intrigue,

We need your input for this thread....
http://www.indigorose.com/forums/showthread.php?t=17073&page=2

Intrigued
09-03-2006, 07:33 PM
Yes, but this duct tape on my mouth (thanks to my wife) keeps me from commenting.

:D

azmanar
09-04-2006, 03:22 AM
oooooooooo .... awesome ...

We'll wait till da gum wears off.