- Get the PLC tags into your function and convert them into
strings. See the simplified example below.
- Use SQLSet (sets up a buffer) as the first function to build up
the first part of the string;
INSERT INTO TABLE
,tag2,tag3,tag4)VALUES(
- Then using SQLAppend, you build up an SQL statement (you could
use one SQLAppend per Tag or String).
- Cicode puts the value as a string into the SQL query, a query
is a string.
- Instead of SQLExec now use SQLExec(hSQL, ""); it then knows to
use the buffered SQL query.
STRING sSQL;
INT hSQL=-1;
FUNCTION
Insert()
String st1=intToStr(CPU_Usage);
String st2=intToStr(FILTER_TANK_LEV);
String st3=intToStr(SugarPLC);
Int Status=0;
hSQL=SQLconnect("DSN=Test");
If hSQL<0 Then
Message("Connect error",
SqlerrMsg(), 48);
Else
SQLSet(hSQL, "INSERT INTO TABLE1
(Tag1,tag2,tag3,tag4)VALUES(");
SQLAppend(hSQL,
st1+","+st2+","+st3+",'Test string')");
Status=SQLExec(hSQL, "");
If Status <> 0 Then
Message("Status
error", SqlerrMsg(), 48);
End
End
SQLDisconnect(hSQL);
END
The above cicode produces the following in a Microsoft Access
database, fields Tag1 to Tag3 are numeric fields and Tag4 is a
string field;
Tag1
|
Tag2
|
Tag3
|
Tag4
|
15
|
37
|
15
|
Test string
|
16
|
42
|
15
|
Test string
|
2
|
48
|
15
|
Test string
|
6
|
51
|
15
|
Test string
|
|