Intrigued
08-30-2006, 06: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
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