SQLite database in MEMORY only!

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • Intrigued
    Indigo Rose Customer
    • Dec 2003
    • 6125

    SQLite database in MEMORY only!

    Note: You will need AMS 5.x Pro and the SQLite plugin installed before you try to view this project!

    I had a couple minutes and wanted to keep my SQLite "sharpness". So, I went ahead and coded this small project file to explain how to create a SQLite database, insert records into it, query it (get a list of data), and then output it (show it up in the Debug window). The neat (well to me anyway) part is that this SQLite database is "memory" loaded only (no files!). Much like a table (array) in AMS 5! But, with the SQLite I like that I can use the SQL on the data and output more easily what I want! Filtering even is easier (get only the data I need/want).
    Please note that I "on purpose" did not include error correction code. This was done to keep it easy to understand how the SQLite plugin works, at least in this one instance.

    But, you should always add error correction code into your projects, not just for the SQLite database!


    [ADDED IN CODE FOR VIEWING]

    Code:
    -- Open the database (db), if it has not already been created
    db = SQLite.Open(":memory:")
    
    -- Create the various tables in the database
    SQLite.Query(db, "CREATE TABLE sqlData(userid INTEGER PRIMARY KEY, LastName TEXT, FirstName TEXT, Country TEXT)")
    
    -- Add some data into the database (db)
    SQLite.Query(db, "Insert into sqlData values(Null, 'Finklestein', 'Roger', 'Utah')")
    SQLite.Query(db, "Insert into sqlData values(Null, 'Ballard', 'Tim', 'California')")
    SQLite.Query(db, "Insert into sqlData values(Null, 'Smortz', 'Barbara', 'Pennsylvania')")
    
    -- Create an AMS table (tblRS) out of the SQLite database (db)
    tblRS = SQLite.QueryToTable(db, "Select * from sqlData")
    
    -- For each row of data (which are numbered) print out all of its data
    for c=1, tblRS.Rows do
    	Debug.ShowWindow(true)
    	Debug.Print(tblRS.Data[c]["userid"]..".\r\n")
    	Debug.Print(tblRS.Data[c]["FirstName"].."\r\n")
    	Debug.Print(tblRS.Data[c]["LastName"].."\r\n")
    	Debug.Print(tblRS.Data[c]["Country"].."\r\n\r\n")
    	
    end
    
    -- 'Not' always needed!  But, it's recommended after manipulating a SQLite database.
    SQLite.Close(db)
    Attached Files
    Last edited by Intrigued; 05-11-2005, 10:13 AM.
    Intrigued
  • yosik
    Indigo Rose Customer
    • Jun 2002
    • 1856

    #2
    Nice snippet, Intrigued.. Thanks!

    Do you have a lot of these "free couple of minutes"?...

    Yossi

    Comment

    • Intrigued
      Indigo Rose Customer
      • Dec 2003
      • 6125

      #3
      Originally posted by yosik
      Nice snippet, Intrigued.. Thanks!

      Do you have a lot of these "free couple of minutes"?...

      Yossi
      Only if I make time for them.

      Intrigued

      Comment

      • Caroline
        Forum Member
        • Sep 2009
        • 5

        #4
        thnk you sir:yes

        Comment

        • degger
          Forum Member
          • Jul 2008
          • 88

          #5
          thx.... :yes:yes

          Comment

          • Intrigued
            Indigo Rose Customer
            • Dec 2003
            • 6125

            #6
            You're welcome. It's good to see posts from years past still relevant and helpful.
            Intrigued

            Comment

            Working...
            X