This tech tip provides two examples of code that demonstrate how to log into an ODBC data source and insert one row of data. The first example uses low-level commands while the second example uses contexts.
- Using Low-level commands
LoginID:=OC Login dialog `Login dialog
$sql:="insert into odbcTable values (?,?,?)" `SQL code with three parameters (??? )
process:=OC Create cursor (LoginID)
$res:=OC Set SQL in Cursor (process;$sql)
$res:=OC Bind parameter (process;1;"[Table1]Field1";1)
$res:=OC Bind parameter (process;2;"[Table1]Field2";1)
$res:=OC Bind parameter (process;3;"[Table1]Field3";1)
$res:=OC Execute cursor (process)
OC LOGOUT (LoginID)
- Using Context
LoginID:=OC `Login dialog
Context_ID:=OC Create context ("odbcTable") `Creates a context to the odbctable
OC ADD TO CONTEXT (Context_ID;"field1";"[Table1]Field1")
OC ADD TO CONTEXT (Context_ID;"field2";"[Table1]Field2")
OC ADD TO CONTEXT (Context_ID;"field3";"[Table1]Field3")
$error1:=OC Activate context (loginID;context_ID)
$error:=OC Insert in context (Context_ID) `creates a new row on the ODBC server
`using 4th Dimension objects that have been specified in context binds
OC DROP CONTEXT (Context_ID)
OC LOGOUT (LoginID)
Note: This Tech Tip assumes that a table named "odbcTable" with three fields already exists on the ODBC Data Source.