It is currently Thu Dec 12, 2019 4:38 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Created database and table but can't create column.
PostPosted: Sun Jun 09, 2019 3:58 pm 
Offline
Enthusiast
Enthusiast

Joined: Wed Sep 10, 2014 7:17 am
Posts: 126
Location: Ontario Canada
I have a database called categories.db which I have opened. The user selects a category from a listview and the selected category is held in a variable called catselection. Now I want to create another database, (sub-category), which will be attached to the categories database. This database will be named by the user using an InputRequester(). When the database is created I want to create a table in the database and the table name will be the same as the database name and will have a column called ‘type’.

I am able to create the database and also the table however, I cannot get the needed column created in the table. Here is the code:

Code:
Procedure addSubCategory()
    Input$ = InputRequester("AddSub-Category", "Sub-Category :", "")
    If Input$ <> ""     
       dbFile = LCase(catselection) + ".db"
       dbTable = LCase(input$)
       dbAlias = LCase(catselection)
       If CreateFile(#dbHandle, dbFile)
         CloseFile(#dbHandle)
         result =  DatabaseUpdate(#dbaseID2, "ATTACH DATABASE '" + dbFile + "' AS '" + dbAlias + "'")
         result = DatabaseUpdate(#dbaseID2, "CREATE TABLE '" + dbTable + "' (type CHAR(30))")           
         query$ = "INSERT INTO '" + dbTable + "' (type) VALUES ('" + Input$ +  "')"
         result = DatabaseUpdate(#dbaseID2, query$)
       If result > 0
         MessageRequester("Add Category", "Category added.", #PB_MessageRequester_Ok)
     Else
         MessageRequester("Add Category", "ERROR: Failed to add Category", #PB_MessageRequester_Ok)
     EndIf
   EndIf
 


I am obviously doing something wrong in the code. Can anyone enlighten me?

Thanks

_________________
Code In Basic - http://www.codeinbasic.com


Top
 Profile  
Reply with quote  
 Post subject: Re: Created database and table but can't create column.
PostPosted: Sun Jun 09, 2019 4:34 pm 
Offline
Enthusiast
Enthusiast

Joined: Sat Feb 08, 2014 3:26 pm
Posts: 718
(Deleted. I misunderstood the question) :?

_________________
(English is not my native language, I use an online translator)
Windows 10 Family x64 + Linux (Slackware, Debian on Oracle VirtualBox 6.0) + Raspberry Pi


Last edited by Marc56us on Sun Jun 09, 2019 4:59 pm, edited 2 times in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Created database and table but can't create column.
PostPosted: Sun Jun 09, 2019 4:34 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Dec 23, 2009 10:14 pm
Posts: 3152
Location: Boston, MA
You can avoid simple and tricky errors by using SQLfiddle or DB Browser for SQLite to try your queries before coding them.
Code:
--ATTACH DATABASE 'dbFilePathName' AS dbAlias;
CREATE TABLE TI (type TEXT, type2 TEXT);
ALTER TABLE TI ADD type3 TEXT;
INSERT INTO TI (type,type2,type3) VALUES('1','2','3');

_________________
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum


Top
 Profile  
Reply with quote  
 Post subject: Re: Created database and table but can't create column.
PostPosted: Sun Jun 09, 2019 11:28 pm 
Offline
Enthusiast
Enthusiast

Joined: Wed Sep 10, 2014 7:17 am
Posts: 126
Location: Ontario Canada
Thank you very much and for the tips on SQL Fiddle and DB_Browser.

_________________
Code In Basic - http://www.codeinbasic.com


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: box_80, juror and 18 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye