Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Snitz Forums 2000 DEV-Group
 DEV Discussions (General)
 Simplified INSERT statements
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

pweighill
Junior Member

United Kingdom
453 Posts

Posted - 27 August 2002 :  09:15:24  Show Profile
The insert statements used in Snitz can be quite long and because of the way insert statements have to be written, the fieldname and datavalue are not together in the code.
That can also make it more difficult to add mods to a forum.

Below are some functions I've written which can make generating INSERT statements simpler.

<%
'inc_SQLinsert.asp
'Purpose to simplify the creation of SQL insert statements.
'Would be neater as a class, but for compatability, written as functions.
'
'To use:
'SetInsertTable strMemberTablePrefix & "MEMBERS"
'AddInsertColumn "M_NAME", "'" & chkString(rsKey("M_NAME"),"SQLString") & "'"
'AddInsertColumn "M_USERNAME", "'" & chkString(rsKey("M_USERNAME"),"SQLString") & "'"
'AddInsertColumn "M_PASSWORD", "'" & chkString(rsKey("M_PASSWORD"),"SQLString") & "'"
'strSQL = ReturnInsertSQL()


Dim strISI_SQLtable
Dim strISI_SQLcolnames
Dim strISI_SQLcolvalues

Sub SetInsertTable(pstrTable)
strISI_SQLtable = pstrTable
strISI_SQLcolnames = ""
strISI_SQLcolvalues = ""
End Sub

Sub AddInsertColumn(pstrColumnName, pstrColumnValue)
strISI_SQLcolnames = strISI_SQLcolnames & ", " & pstrColumnName
strISI_SQLcolvalues = strISI_SQLcolvalues & ", " & pstrColumnValue
End Sub

Function ReturnInsertSQL()
ReturnInsertSQL = "INSERT INTO " & strISI_SQLtable & " (" & mid(strISI_SQLcolnames,3) & ") VALUES (" & mid(strISI_SQLcolvalues,3) & ")"
End Function
%>

Edited by - pweighill on 27 August 2002 09:15:56

ruirib
Snitz Forums Admin

Portugal
26364 Posts

Posted - 27 August 2002 :  09:30:48  Show Profile  Send ruirib a Yahoo! Message
This can make it easier alright, but will also mean I don't know how many extra sub calls throughout the code.

Personnally I prefer to do it the way it has been done so far.


Snitz 3.4 Readme | Like the support? Support Snitz too

Edited by - ruirib on 27 August 2002 09:31:28
Go to Top of Page

Deleted
deleted

4116 Posts

Posted - 27 August 2002 :  09:40:30  Show Profile
How do you insert different data types (text, number, date) with different databases?

Stop the WAR!
Go to Top of Page

pweighill
Junior Member

United Kingdom
453 Posts

Posted - 27 August 2002 :  09:48:22  Show Profile
quote:
Originally posted by bozden

How do you insert different data types (text, number, date) with different databases?



You don't need to in worry about different data types

e.g.
AddInsertColumn "textfield", "'textvalue'"
AddInsertColumn "numberfield", "0"

And date type data doesn't exist in Snitz, it's just text.
Go to Top of Page

HuwR
Forum Admin

United Kingdom
20584 Posts

Posted - 27 August 2002 :  09:49:06  Show Profile  Visit HuwR's Homepage
I don't see how what you propose would simplify matters at all, you know have three functions to debug instead of a block of text, plus as bozden said, your example would only work if your data type was a number/integer
Go to Top of Page

Deleted
deleted

4116 Posts

Posted - 27 August 2002 :  09:59:14  Show Profile
Actually the problem is caused by constructs like:


strSql = strSql & ", T_STATUS"
if strIPLogging <> "0" then
strSql = strSql & ", T_IP"
end if
if ForumChkSkipAllowed = 1 then
strSql = strSql & ", T_STICKY"
end if
strSql = strSql & ", T_SIG"


I.e. we have a lot of configuration related flags, thus we need to have if-then-else structures which makes it difficult to read.

Stop the WAR!
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.2 seconds. Powered By: Snitz Forums 2000 Version 3.4.07