...
These techniques can be used when reading or writing to a database using SQL statements in the Translator.
Expand |
---|
title | String concatenation can be used for simple SQL statements. |
---|
|
Simple string concatenation can be used for simple SQL statements. Code Block |
---|
local result = conn:query{sql='SELECT * FROM Patients WHERE LastName=' ..conn:quote(lastName)} |
|
Expand |
---|
title | table.concat can be used to concatenate multiple values from a table into a SQL statement. |
---|
|
In this example, each value is escaped and then concatenated into the SQL statement. Code Block |
---|
| local values = {'John', "O'Reilly", '1980-01-01', 'Male'}
-- Loop through table of values
local T = {}
for i, v in ipairs(values) do
T[i] = conn:quote(v)
end
-- Execute SQL Insert
local sqlInsert = 'INSERT INTO Patients (FirstName, LastName, DOB, Gender) VALUES ('..table.concat(T, ', ')..')'
local results = conn:execute{sql=sqlInsert, live=true} |
In the Annotations you can see: |
...