Add To Database - Posted (2390 Views)
Senior Member
leatherlips
Posts: 1838
1838
I am working on a mod but I need to be able to add some items to the database. How do you add a new section to the database? Also, how do you add an item that is either a yes or no choice? And for the final question (I think), how do you make several choices from the database available as a dropdown?
 Sort direction, for dates DESC means newest first  
 Page size 
Posted
Advanced Member
Carefree
Posts: 4224
4224
Well, you packed a lot into a 2 line query. lol

First, to add a new section to the database. Do you need a new table or new fields in an existing table? That is done using a dbs form. We'll use extracts from the auction mod dbs file for an example.

Code:

Auction Mod Version 2.6

[DROP] AUCTIONBIDS
[END]

The drop command deletes a table (if it exists, command ignored if table not found). All commands must be closed with the End command.
Code:

[CREATE]
AUCTIONFEEDBACK

AUCTIONID#int#NOT NULL#
BUYERID#int#NULL#
SELLERID#int#NULL#
BUYERSCORE#int#NULL#
SELLERSCORE#int#NULL#
BUYERCOMMENT#varchar(50)#NULL#
SELLERCOMMENT#varchar(50)#NULL#
DATEBUYER#varchar(20)#NULL#
DATESELLER#varchar(20)#NULL#
[END]

The Create command makes a new table. The table title is the second line. A blank line is left if no index field is required, otherwise the third line is the index field's information.
Field definitions follow until the last field is added, then use the End command to close. Definition formats: field title, # sign (separates each part of definition), field format (varchar = text, the length of the text field in parentheses following - limit 255), (int = integer, no field length), (smallint = values 0 to 65535), memo (for text fields that can exceed 255 chars, no field length), # sign, NULL (if null allowed, leave blank or use "NOT NULL" if not), # sign, default value (leave blank if none), # sign (if default value left blank).

Code:

[INSERT]
AUCTIONCATEGORIES
(CATEGORYNAME,CATEGORYDESCRIPTION)#('Motor','All types of Motor vehicles')
[END]

To modify existing field values in a table, use the Insert command. The second line is the table name again, then use as many lines as required in this format:
Opening parenthesis, fieldname, comma, field name, comma, etc., closing parenthesis, # sign, opening parenthesis, value, comma, value, comma, etc., closing parenthesis
Close command with the End command again.
Code:

[DELETE]
CONFIG_NEW
(C_VARIABLE="TPID")
[END]
The Delete command is used to delete records from a database. First line is the command, next, the table, third: opening parenthesis, fieldname,= sign, field value to match (Note: if the field is a string type, value should be in quotation marks, if numeric, just the number value), closing parenthesis. Continue with each record to delete, close with End command.

Use a separate Delete command to delete records from different tables.
Code:

[ALTER]
MEMBERS
DROP#M_REQUIRED###
ADD#M_REQUIRED#VARCHAR(10)##0
[END]

The Alter command is used to add/delete fields from a table. Format:
command, table name, then action lines, and close with End command.
Drop (delete field), # sign, fieldname, ###
Add (add field), # sign, fieldname, # sign, field type (see field definitions above from Create command), # sign, NULL or NOT NULL/blank, # sign, default value or blank, # sign (if default value left blank).
Finally, the Update command:

Code:

[UPDATE]
CONFIG_NEW
C_VALUE#'Ver 2.4.4'#C_VARIABLE='STRIPGATEVER'
[end]

Updates records. Format: command, table name, update lines, close with End command.
Update line format:
Field name, # sign, New Value, # sign, Where clause (specify condition to meet - in this case, "c_Variable" had to equal a string value of STRIPGATEVER).
... how do you make several choices from the database available as a dropdown?

That's best done in the program itself. More flexibility.
Posted
Senior Member
leatherlips
Posts: 1838
1838
Thanks Carefree for the lesson. I'll have to study it a bit more to figure out how to do what I want to do. smile
Posted
Advanced Member
Carefree
Posts: 4224
4224
Send me Email and I'll try and help you without posting 400 messages as it's developed.
Posted
Senior Member
leatherlips
Posts: 1838
1838
Posted
Forum Admin
HuwR
Posts: 20611
20611
If the database type is Access, you could use field type "Yes/No"
You should stick to the standard field types that the forum uses, it does not use yes/no fields, you should use an int or smallint field and give it values of 1 or 0 to denote true or false
Posted
Forum Admin
HuwR
Posts: 20611
20611
here is the official instructions for using dbs files http://forum.snitz.com/forum/topic.asp?TOPIC_ID=25296
some of carefree's instructions are not 100% accurate.
(Note: if the field is a string type, value should be in quotation marks, if numeric, just the number value),
example shows double quotes but should be single quotes
Posted
Senior Member
leatherlips
Posts: 1838
1838
Here is a mock up of what I am trying to do:

Code:
My Test MOD 2.0

[CREATE] TEST_MOD

on#int#NULL#0
grouping#int#NULL#0
style1#int#NULL#DEFAULT
style2#int#NULL#1
style3#int#NULL#1
[END]

I'm trying to create a new table TEST_MOD. In it I want different columns.
The on column will tell the mod to be on or off via an admin panel. The grouping column will tell the mod how to group one of two ways via an admin panel. The style columns will be available in a dropdown via the admin panel. Style1 should be the default choice when style2 and style3 are not selected.
I've tried my code above in a file called dbs_mytestmod.asp and run it but it does not create the table. I get this:


I check my database and the table is not there. Also, if I then drop the table it say's the table does not exist.
Posted
Advanced Member
Carefree
Posts: 4224
4224
You have to use a different word than "on". Since "On" is restricted in the following languages: Jet, MS Access, MS ANSI, MS ODBC, MS SQL Server 2000, MS SQL Server 2005, MS SQL Server 2008, My SQL, OLAP, Oracle, Postgre SQL, Postgre SQL 1992, Postgre SQL 1999, Postgre SQL 2003, Sybase, you're going to experience errors.

Posted
Advanced Member
Carefree
Posts: 4224
4224
You're welcome.
 
You Must enter a message