On Fri, Mar 26, 2010 at 07:33:31AM +0000, Brett Parker wrote:
On 25 Mar 20:00, Chris G wrote:
I know it isn't really necessary as it doesn't actually affect anything (except my sensibilities) but I'd like the ability to re-order columns in some sqlite databases.
Well, it *does* have some advantages, it would mean I can do things like "SELECT * FROM database" and get the columns displayed in the order I want rather than the order resulting from database creation followed by adding extra columns as I found I needed them.
So, is there any way to re-order columns other than by creating a new table with the required column order, copying all the data across, deleting the old table and renaming the new one?
I can't find any neat utilities out there to do this for me.
When are you using a sqlite database and interfacing to it with something that isn't a programming language? Most languages with a database api will allow you to collect results from the database in a 'hashmap' or 'dictionary' with the column name as the key.
I'm interfacing to it from a Wiki so that, while I have *some* programming ability it's pretty limited.
Also, if you're adding lots of columns, you probably want to be more selective which are displayed if you are accessing it from the command line sqlite program, i.e. using: SELECT field1,field2 from mytable where <some condition>; Rather than the * approach.
What I'm doing is using the database to provide data storage for information in the Wiki, the ordering of columns as displayed in the Wiki is, of course, under the control of the Wiki.
However when I browse the data in the database using tools like sqlitebrowser and sqliteman it would be really nice to see the database columns in a sensible order with the most important column(s) first so they're immediately visible.
I can create a database browsing page in the Wiki which shows all columns in the order I want and allows me to change the data but it doesn't provide the facilities of sqlitebrowser and sqliteman to add/delete/change columns.