Indigo Rose Software

Professional Software Development Tools

 
+ Reply to Thread
Results 1 to 8 of 8
  1. #1
    Join Date
    May 2005
    Posts
    1,115

    SQLite Alter Table script

    Alter table (rename / add columns) support for SQLite 2.8 and IndigoRose AutoPlay Media Studio

    SQLiteAddColumns accepts the following attributes:
    1: SQLite database handle
    2: SQLite table name
    3: an array with new column names as indexes and column types as strings
    4: name of the primary key column (default: 'id')
    5: whether to keep the temporary table used in the process (default: false)

    There is also a function SQLiteRenameTable(db, oldname, newname, primarykey) at your disposal.

    Please note that the processing time of adding a new column to the table depends on the amount of data in your table. In order to implement alter table for the 2.x SQLite, data must be first writen to the temporary table, and than again to the original one!

    WARNING: Any triggers or indexes you have on your table will be LOST, so make sure you recreate them after using either SQLiteAddColumns or SQLiteRenameTable functions!

    Attached script version: 0.9.
    It should work fine, but please test it a bit. It assumes you use SQLite 2 plugin bundled with APMS.
    Also, please rename the file extension to .lua
    Attached Files
    Never know what life is gonna throw at you.
    (Based on a true story.)

  2. #2
    Join Date
    Apr 2007
    Location
    Raalte, OV, Netherlands
    Posts
    3,287
    Impressive, thanks.
    Bas Groothedde
    Imagine Programming :: Blog :: Familiar people here

    My AMS Plugins:

  3. #3
    Join Date
    Jul 2002
    Location
    Just South of Reality
    Posts
    778
    Very nice Bule. This is a true time saver for anyone who uses Sqlite.
    Thanks for sharing this gem.

  4. #4
    Join Date
    May 2005
    Posts
    1,115
    The following two functions were missing in the upper script:

    Code:
    -- string manipulation before saving it in the database:
    function Q(str) 
    	local s=str.."";
    	s=String.Replace(s, "'", "''", false);
    	return s;
    end
    
    -- string decoding after reading it from the database:
    function QD(str)
    	return tostring(str or "");
    end
    I use these to replace single quotes with two of the same kind (you can not use single quote in the string because it's a key word for string start/end). You can also do your own additional modification to the strings stored in the database here (at least I do it).
    Last edited by bule; 05-30-2009 at 10:58 AM.
    Never know what life is gonna throw at you.
    (Based on a true story.)

  5. #5
    Join Date
    May 2005
    Posts
    1,115
    This one was missing as well:

    Code:
    function Num(str)
    	return String.ToNumber((str or 0).."");
    end
    Never know what life is gonna throw at you.
    (Based on a true story.)

  6. #6
    Join Date
    Apr 2007
    Location
    Raalte, OV, Netherlands
    Posts
    3,287
    Quote Originally Posted by bule View Post
    This one was missing as well:

    Code:
    function Num(str)
    	return String.ToNumber((str or 0).."");
    end
    Code:
    Num = tonumber;
    that's what I used
    Bas Groothedde
    Imagine Programming :: Blog :: Familiar people here

    My AMS Plugins:

  7. #7
    Join Date
    May 2005
    Posts
    1,115
    Nice one... I use Num a lot, it's short and convenient!
    Never know what life is gonna throw at you.
    (Based on a true story.)

  8. #8
    Join Date
    Apr 2007
    Location
    Raalte, OV, Netherlands
    Posts
    3,287
    Your right about that, i got used to tonumber and tostring
    Bas Groothedde
    Imagine Programming :: Blog :: Familiar people here

    My AMS Plugins:

Similar Threads

  1. Alter Table function?
    By bule in forum AutoPlay Media Studio 7.5
    Replies: 1
    Last Post: 04-08-2009, 03:28 PM
  2. SQLite count number of table rows
    By Shide in forum AutoPlay Media Studio 7.5
    Replies: 7
    Last Post: 03-26-2009, 04:19 AM
  3. Including CrystalReport VS2005
    By Calisana in forum MSI Factory 2.0 Discussion
    Replies: 3
    Last Post: 03-17-2009, 09:28 AM
  4. SQLite won't Alter Table
    By pjborg in forum AutoPlay Media Studio 7.5
    Replies: 10
    Last Post: 06-28-2008, 08:59 AM
  5. Fading effect with Labels
    By autoplmst6 in forum AutoPlay Media Studio 7.5 Examples
    Replies: 3
    Last Post: 04-09-2008, 03:18 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts