*To the mods: I wasn't sure where to put this, so I put it here because this is where most of the mysql.dll questions are at. If you feel it belongs somewhere else, just delete and let me know where.
After downloading mysql.dll and spending 3 days learning what commands inserted and deleted data and thier syntax I made this program to write the functions for me. I figured I would put it up here incase someone else is having as much trouble as I did.
Just unzip the program to the folder of your project and run function maker.exe. It will then ask you some basic questions and make a txt file with the name you gave the function. (IE mySQL_INSERT.txt) cut and paste and your done. I also included a copy of libmysql.dll so you wont have to install mysql to get it.
Test Run:
as a test enter these settings.
question #1: 1
question #2: mySQL_INSERT_TEST
question #3: 3
question #4: id#
question #5: name$
question #6: rank#
question #7: www.test.server.com
question #8: test_user
question #9: test_pass
question #10: test_table
question #11: id
question #12: name
question #13: rank
question #14: INT
question #15: CHAR
question #16: INT
question #17: 25
question #18: 10
question #19: 5
and that will give you a template to look at and understand what's going where.
download size: 414kb
for those on dial-up,
here is the source:
*Note: excuse the sloppy source, I was up for 48 hours and wrote this in 1 hour so it isn't neat.
Rem Project: Function_Maker
Rem Created: 4/24/2005 2:21:54 AM
Rem ***** Main Source File *****
`// mySQL function maker
set display mode 1024,768,16
`// global variables
global funcName$
global server$
global uName$
global uPass$
global tableName$
`// arrays
dim function_array$(65)
`// Ask the questions
print
print
print "Would you like to create a mySQL function to INSERT data, or DELETE data?"
print
print "1: INSERT / 2: DELETE"
print
input "Please choose: ",selected
print
print
input "Please enter the functions name: ",funcName$
print
input "Please enter the number of variables you would like to pass to the function: ",temp_variables$
print
`// make a new array to hold all the variable names.
dim variables$(val(temp_variables$))
for x = 1 to val(temp_variables$)
input "Please enter variable #"+str$(x)+"'s name: ",temp_variable$
variables$(x) = temp_variable$
next x
print
input "Please enter a server address. (Either IP or address such as www.msn.com): ",server$
print
input "Please enter a users name for the database. (Please make sure the username has write privileges): ",uName$
print
input "Please enter the password for the above entered username: ",uPass$
print
input "Please enter the new tables name: ",tableName$
print
print "The number of subtables matches the number of variables coming into the function."
print
print "I recommend that you name your tables the same as the variables passed to the function. It's easier to remember them that way"
print
temp_tables$ = temp_variables$
print
`// make a new array for all the sub table names
dim value$(val(temp_tables$))
for x = 1 to VAL(temp_tables$)
input "Please enter the name of subtable #"+str$(x)+": ",temp_value$
value$(x) = temp_value$
next x
print
`// make a new array for the types
dim type$(val(temp_tables$))
for x = 1 to VAL(temp_tables$)
input "Please enter the "+addQuotes("type")+" for subtable #"+str$(x)+". (IE CHAR, INT, FLOAT) ",temp_type$
type$(x) = temp_type$
next x
print
`// make a new array for the maximum number of characters per type
dim number$(val(temp_tables$))
for x = 1 to val(temp_tables$)
input "Please enter the maximum number of characters allowed in each type of subtable: ",temp_numbers$
number$(x) = temp_numbers$
next x
print
`// make the function
function_array$(0) = "function "+funcName$+"("
function_array$(1) = " `// start mySQL dll"
function_array$(2) = " handle=mySQL_Initialise()"
function_array$(3) = " if handle=0"
function_array$(4) = " blowOut("+addQuotes("mySQL Initialisation Error")+")"
function_array$(5) = " exit"
function_array$(6) = " endif"
function_array$(7) = return_break()
function_array$(8) = " `// connect to the database on the server"
function_array$(9) = " handle2=mySQL_Connect(handle,"+addQuotes(server$)+","+addQuotes(uName$)+","+addQuotes(uPass$)+","+addQuotes(tableName$)+","+str$(0)+","+addQuotes("")+","+str$(0)+")"
function_array$(10) = " if handle2<>handle"
function_array$(11) = " blowOut("")"
function_array$(12) = " exit"
function_array$(13) = " endif"
function_array$(14) = return_break()
function_array$(15) = " `// create the new table if it does not exits with the subtables "+addQuotes("sub_1")+","+addQuotes("sub_2")+", and "+addQuotes("sub_3")+" ect..ect..."
function_array$(16) = " query$="+addQuote("CREATE TABLE IF NOT EXISTS "+tableName$+" (")
function_array$(17) = " queryHandle=mySQL_Query(handle,query$)"
function_array$(18) = return_break()
function_array$(19) = " `// insert the information in the correct tables"
function_array$(20) = " if queryHandle=0"
function_array$(21) = " query$="+addQuote("INSERT INTO "+tableName$+" (")
function_array$(22) = " queryHandle=mySQL_Query(handle,query$)"
function_array$(23) = " if queryHandle<>0"
function_array$(24) = " blowOut("+addQuotes("")+")"
function_array$(25) = " exit"
function_array$(26) = " endif"
function_array$(27) = " else"
function_array$(28) = " blowOut(""):rem unable to create the initial table."
function_array$(29) = " exit"
function_array$(30) = " endif"
function_array$(31) = return_break()
function_array$(32) = " `Shut everything down"
function_array$(33) = " mySQL_Close handle"
function_array$(34) = "endfunction"
function_array$(35) = return_break()
function_array$(36) = "function addQuotes(text$ as string)"
function_array$(37) = " a$=chr$(34)+text$+chr$(34)"
function_array$(38) = "endfunction a$"
function_array$(39) = return_break()
function_array$(40) = "function addQuote(text$ as string)"
function_array$(41) = " b$=chr$(34)+text$"
function_array$(42) = "endfunction b$"
function_array$(43) = return_break()
function_array$(44) = "function addEndQuote(text$ as string)"
function_array$(45) = " c$=text$+chr$(34)"
function_array$(46) = "endfunction c$"
function_array$(47) = return_break()
function_array$(48) = "function addSingleQuotes(text$ as string)"
function_array$(49) = " d$=chr$(39)+text$+chr$(39)"
function_array$(50) = "endfunction d$"
function_array$(51) = return_break()
function_array$(52) = "function addThingy(text$ as string)"
function_array$(53) = " e$=chr$(96)+text$+chr$(96)"
function_array$(54) = "endfunction e$"
function_array$(55) = return_break()
function_array$(56) = "`// the addThingy function just adds one of these characters: " +addQuotes(chr$(96))+ ", that's the key to the left of 1 without caps!"
function_array$(57) = return_break()
function_array$(58) = "function blowOut(error$ as string)"
function_array$(59) = " if error$<>"+addQuotes("")
function_array$(60) = " print error$"
function_array$(61) = " else"
function_array$(62) = " print "+addquotes("mySQL Error :")+";mySQL_GetLastError$(handle);"+addQuotes(" ")+";mySQL_GetLastErrorInt(handle)"
function_array$(63) = " endif"
function_array$(64) = " wait key"
function_array$(65) = "endfunction"
for x = 1 to val(temp_variables$)
if val(temp_variables$) = 1
function_array$(0) = function_array$(0)+variables$(x)+")"
endif
if x = val(temp_variables$)
function_array$(0) = function_array$(0)+variables$(x)+")"
else
function_array$(0) = function_array$(0)+variables$(x)+","
endif
next x
for x = 1 to val(temp_tables$)
if val(temp_tables$) = 1
function_array$(16) = function_array$(16)+value$(x)+" "+type$(x)+ " "+"("+number$(x)+")"+addEndQuote(")")
endif
if x = val(temp_tables$)
function_array$(16) = function_array$(16)+value$(x)+" "+type$(x)+ " "+"("+number$(x)+")"+addEndQuote(")")
else
function_array$(16) = function_array$(16)+value$(x)+" "+type$(x)+ " "+"("+number$(x)+")"+","
endif
next x
if selected = 1
for x = 1 to val(temp_tables$)
if val(temp_tables$) = 1
function_array$(21) = function_array$(21)+value$(x)
endif
if x = val(temp_tables$)
function_array$(21) = function_array$(21)+value$(x)
else
function_array$(21) = function_array$(21)+value$(x)+","
endif
next x
function_array$(21) = function_array$(21)+") VALUES"+addEndQuote("(")
for x = 1 to val(temp_tables$)
proof$ = var_test(variables$(x))
if val(temp_tables$) = 1
function_array$(21) = function_array$(21)+"+addQuotes("+proof$+")"+"+"+addQuotes(")")
endif
if x = val(temp_tables$)
function_array$(21) = function_array$(21)+"+addQuotes("+proof$+")"+"+"+addQuotes(")")
else
function_array$(21) = function_array$(21)+"+addQuotes("+proof$+")"+"+"+chr$(34)+","+chr$(34)
endif
next x
else
dim function_array_2$(0)
function_array_2$(0) = " query$="+addQuotes("DELETE FROM "+tableName$+" WHERE ")
for x = 1 to val(temp_tables$)
proof$ = var_test(variables$(x))
if val(temp_tables$) = 1
function_array_2$(0) = function_array_2$(0)+"+addThingy("+addQuotes(value$(x))+")"+"+"+addQuotes("=")+"+addSingleQuotes("+proof$+")"+"+"+"addQuotes("")"
endif
if x = val(temp_tables$)
function_array_2$(0) = function_array_2$(0)+"+addThingy("+addQuotes(value$(x))+")"+"+"+addQuotes("=")+"+addSingleQuotes("+proof$+")"+"+"+"addQuotes("")"
else
function_array_2$(0) = function_array_2$(0)+"+addThingy("+addQuotes(value$(x))+")"+"+"+addQuotes("=")+"+addSingleQuotes("+proof$+")"+"+"+addQuotes(" AND ")+""
endif
next x
function_array$(21) = function_array_2$(0)
endif
`// print the new function to the screen and save it to a file.
for x = 0 to array count(function_array$())
print function_array$(x)
next x
save array funcName$+".txt",function_array$()
print "This screen print out has been saved to "+funcName$+".txt in "
print get dir$()+" "
wait key
end
function addQuotes(text$ as string)
a$=chr$(34)+text$+chr$(34)
endfunction a$
function addQuote(text$ as string)
b$=chr$(34)+text$
endfunction b$
function addEndQuote(text$ as string)
c$=text$+chr$(34)
endfunction c$
function addSingleQuotes(text$ as string)
d$=chr$(39)+text$+chr$(39)
endfunction d$
function addThingy(text$ as string)
e$=chr$(96)+text$+chr$(96)
endfunction e$
function return_break()
f$=chr$(0)
endfunction f$
function var_test(var$)
if mid$(var$,len(var$)) <> "$"
temp_temp_variable$=var$
str_variables$ = "STR$("+temp_temp_variable$+")"
else
str_variables$ = var$
endif
endfunction str_variables$
if you compile your own, you must get your own libmysql.dll file to place in your projects folder because I can only upload one file.
Phrozin