varaible value has apostrophe ACCESS VBA - apostrophe

With a for loop in VBA I would like to write values of an array into a table in ACCESS, but the array values has apostrophe, therefore the SQL is not working in VBA
Arr(1) = "Mother' love"
Arr(2) = "Father' love"
Arr(3) = "Value in 'Mother'"
Arr(4) = "Value in 'Father'"
For i = 1 To 4 Step 1
strSQL = "Insert into [Table1] (Content) Values (" & Arr(i) & ")"
Debug.Print strSQL
DoCmd.RunSQL strSQL
Application.RefreshDatabaseWindow
Next i
Errors as follow
Run-time error '3075'
Syntax error (missing operator) in query expression 'Mother's love)'

Related

Getting sorted data from a table in LUA

I am trying to wrap my head around how tables work in Lua, but it is very confusing.
I am pulling data out of an existing table of strings, with an index number for each string. However the numbers are not consecutive. So my data looks like this:
mytable[0] = "the first string"
mytable[5] = "the second string"
mytable[13] = "the third string"
mytable[29] = "the fourth string"
I want to take each of these strings, concatenate the index number onto them and output them all into a single new string, like this:
"0: the first string\n,
5: the second string\n
13: the third string\n
29: the fourth string"
If I access the data using pairs, then I get the items out of order, and it is very important that they remain in order.
If I access the data using ipairs, it doesn't work because there are gaps in the index numbers.
How would I go about getting the data from the table into a string, while keeping it all in order?
You can do what Cássio says about creating a new array, or (just in case you are interested on an alternative method) you also could do something like this:
<script src="//github.com/fengari-lua/fengari-web/releases/download/v0.1.4/fengari-web.js"></script>
<script type="application/lua">
local mytable = {}
local myvalues = ""
local mystring = ""
mytable[0] = "the first string"
mytable[5] = "the second string"
mytable[13] = "the third string"
mytable[29] = "the fourth string"
for i = 0, 29 do --or any "reasonable" limit you don't expect to reach, like maybe 99 in this case?
myvalues = mytable[i] or nil
if myvalues then
mystring = mystring .. i .. ": " .. myvalues .. "\n"
end
end
print(mystring)
</script>
Which in this case results in:
0: the first string
5: the second string
13: the third string
29: the fourth string
But you could easily format the resulting string as you want... A less canonical way to do it, but there it is just in case it helps.
EDIT: Added as a Lua "snippet" just for the sake of testing it (🙄🤞)

Grails Sql executeUpdate with array as parameter

I have this statement:
sql.executeUpdate("UPDATE outbound_message set acknowledged = true, acknowledged_date = NOW(), acknowledged_from = '" + userNameToUse + "' where id in(" + msgList + ") and acknowledged = false")
msgList is a string like 2,4,5 containing the ids.
How can I make this as a prepared statement?
I tried:
long[] test = [1,2]
sql.executeUpdate("UPDATE outbound_message set acknowledged = true, acknowledged_date = NOW(), acknowledged_from = :user where id in(:list) and acknowledged = false", [user:userNameToUse, list:test])
I get this exception:
org.postgresql.util.PSQLException: ERROR: operator does not exist: bigint = bigint[]
Hint: No operator matches the given name and argument types. You might need to add explicit type casts.
How can I perform a IN() with a prepared statement?

Psql - How to skip row when error in address during Geocoding

Am Geocoding hundreds of thousands of records, while this query is running if the address does not produce a Lat and Long value for a particular row it shows an error "invalid input syntax for integer: "J199" ". So if this line
(geocode_intersection(crashroad,crashreferenceroad,state,city,'',1)
Produces a value like "J199",it has to skip that row. So how to do this?
update nj.condition_3
set (rating,new_address,points) = ( COALESCE((g.geo).rating,-1),pprint_addy((g.geo).addy),st_astext(ST_SnapToGrid((g.geo).geomout, 0.000001)))
-- Replace in limit value if error occurs
FROM (SELECT addid FROM nj.condition_3 WHERE rating IS NULL ORDER BY addid LIMIT 3) As a
LEFT JOIN (SELECT addid, (geocode_intersection(crashroad,crashreferenceroad,state,city,'',1)) As geo
-- Replace in limit value if error occurs
FROM nj.condition_3 As ag WHERE ag.rating IS NULL ORDER BY addid LIMIT 3) As g ON a.addid = g.addid
WHERE a.addid = nj.condition_3.addid;
I have written a function to overcome this Error. So now it is working fine.
CREATE OR REPLACE FUNCTION geocode_all_values() RETURNS VOID AS
$$
DECLARE
r record;
g record;
BEGIN
FOR r IN select * from TableName where rating is null order by Sno
LOOP
BEGIN
FOR g IN select * from geocode_intersection(r.Street1,r.Street2,r.state,r.city,'',1)
LOOP
update TableName
set new_address = pprint_addy(g.addy),
rating = g.rating,
points = ST_AsTEXT(g.geomout)
where sno = r.sno;
END LOOP;
EXCEPTION WHEN OTHERS THEN
END;
END LOOP;
END;
$$
LANGUAGE plpgsql;

Inserting rows into existing Excel worksheet with OleDbConnection

I'm building insert statements based on a list of data and a tab name. I have 4 tabs, the last 2 get data inserted successfully, the first 2 do not.
I commented out inserting into all tabs but one. The size of the excel file increases, but the rows are still blank. Any ideas?
Edit: For some reason, the Excel file I was using as a "blank template" had "empty" values in rows of the first 2 sheets. First one had "empty values" in the first 100K rows, seconds had empty values in the first 700-some rows. The data was being inserted after these rows, which explains why the file size was increasing. Now I'm getting "Operation must use an updateable query" when trying to insert.
Public Sub BuildReport(Of T)(tabName As String, dataList As IEnumerable(Of T))
'// Setup the connectionstring for Excel 2007+ XML format
'// http://www.connectionstrings.com/ace-oledb-12-0/
If ((tabName.EndsWith("$") = True AndAlso m_TabList.Contains(tabName) = False) OrElse m_TabList.Contains(tabName & "$") = False) Then
Throw New Exception(String.Format("The specified tab does not exist in the Excel spreadsheet: {0}", tabName))
End If
Using excelConn As New OleDbConnection(m_ConnectionString)
excelConn.Open()
Dim insertStatementList As IEnumerable(Of String) = BuildInsertStatement(Of T)(tabName, dataList)
Using excelCommand As New OleDbCommand()
excelCommand.CommandType = CommandType.Text
excelCommand.Connection = excelConn
For Each insertStatement In insertStatementList
excelCommand.CommandText = insertStatement
excelCommand.ExecuteNonQuery()
Next
End Using
End Using
End Sub
Private Function BuildInsertStatement(Of T)(tabName As String, dataList As IEnumerable(Of T)) As IEnumerable(Of String)
Dim insertStatementList As New List(Of String)
Dim insertStatement As New StringBuilder()
For Each dataItem As T In dataList
Dim props As PropertyInfo() = GetType(T).GetProperties()
insertStatement.Clear()
insertStatement.AppendFormat("INSERT INTO [{0}$] ", tabName)
Dim nameValueDictionary As New Dictionary(Of String, String)
For Each prop As PropertyInfo In props
Dim excelColumn As ExcelColumnAttribute = CType(prop.GetCustomAttributes(GetType(ExcelColumnAttribute), False).FirstOrDefault(), ExcelColumnAttribute)
If (excelColumn IsNot Nothing) Then
Dim value As Object = prop.GetValue(dataItem, Nothing)
If (value IsNot Nothing AndAlso value.GetType() <> GetType(Integer) _
AndAlso value.GetType() <> GetType(Double) _
AndAlso value.GetType() <> GetType(Decimal) _
AndAlso value.GetType() <> GetType(Boolean)) Then
value = String.Format("""{0}""", value)
ElseIf (value Is Nothing) Then
value = "NULL"
End If
nameValueDictionary.Add(excelColumn.ColumnName, value)
End If
Next
Dim columList As String = String.Join(",", nameValueDictionary.Keys)
Dim valueList As String = String.Join(",", nameValueDictionary.Select(Function(x) x.Value))
insertStatement.AppendFormat("({0}) ", columList)
insertStatement.AppendFormat("VALUES ({0})", valueList)
insertStatementList.Add(insertStatement.ToString())
Next
Return insertStatementList
End Function
For some reason, the Excel file I was using as a "blank template" had "empty" values in rows of the first 2 sheets. First one had "empty values" in the first 100K rows, second one had empty values in the first 700-some rows. The data was being inserted after these rows, which explains why the file size was increasing. Now I'm getting "Operation must use an updateable query" when trying to insert.
I found the answer to the second problem here: Operation must use an updateable query when updating excel sheet
Just needed to remove the "IMEX=1" from the extended properties of the connection string which I added in trying to troubleshoot the issue.

update table that contains single quote symbol with different online server in informix 4 gl

hi all,I am working on informix-4gl.my programs is about to adds and update user information from one tables to many tables.The tables are also must be update from different online server.The main tables is working on online06 named 'crsell' table and the other tables are on the online03 named 'cmpurc' table.This an example on how i update the tables.
## update CMPURC with latest purchaser info ##
LET ins_01 = NULL
LET ins_01 = "UPDATE bfs#", link_onln_no CLIPPED, ":cmpurc",
" SET cmp_purc_num = ", "'", p_cm_purc_num,
"'",",",
" cmp_purc_nme = ", "'",p_cmp_purc_nme,
"'",",",
" cmp_addr_1 = ", "'",p_cmp_addr_1, "'",",",
" cmp_addr_2 = ", "'",p_cmp_addr_2, "'",",",
" cmp_addr_3 = ", "'",p_cmp_addr_3, "'",
" WHERE cmp_proj_cde = ", "'", p_crsell.crse_proj_cde,
"'",
" AND cmp_phase_num = ", "'", p_crsell.crse_phase_num,
"'",
" AND cmp_lot_num = ", "'", p_crsell.crse_lot_num, "'"
In case, there were information from user that contains "'" symbol or single quote such as the purchaser name or user address.My problems is when I update the tables,the information that contains single quote symbols will not updated to the 'cmpurc' tables on online03 server. there will show an error message SQL statement error number -201.
I had try to convert symbol "'" to other symbol "^" and update the tables.Then, I update again the 'cmpurc' table with the information that contains "'" symbols.This step are also produce an error.This is way on how i convert the symbol.
LET rmks_lgth = LENGTH(p_crsell.crse_purc_nme)
FOR a = 1 TO rmks_lgth
IF p_crsell.crse_purc_nme[a] = "'" THEN
LET p_crsell.crse_purc_nme[a] = "^"
END IF
END FOR
convert back to single quotes symbol
LET rmks_lgth = LENGTH(p_cmp_purc_nme)
FOR a = 1 TO rmks_lgth
IF p_cmp_purc_nme[a] = "^" THEN
LET p_cmp_purc_nme[a] = "'"
END IF
END FOR
i had test by replacing the "'" symbol with the other values and its produce no error. The error will only occurs when the "'" symbol are being transfer from table 'crsell' to 'cmpurc'.I hope that someone can help me to solve my problems.I am sorry if there is lack of information that i had given to you because i cant post the image because lack of reputation and i am new user .I am very appreciate if you all can help me to solve the problems. thank you very much
Now, I am going to change single quotes to double quotes.I had try change code like this but its reads only single quotes.anyone can give an idea? thank you
LET rmks_lgth = LENGTH(p_crsell.crse_purc_nme)
FOR a = 1 TO rmks_lgth
IF p_crsell.crse_purc_nme[a] = "'" THEN
LET p_crsell.crse_purc_nme[a] = "''"
END IF
END FOR
I believe you need to duplicate the quote or double quote to get just one without syntax error...
This example I run into dbaccess without problem, I don't test into 4gl code...
create temp table tp01( desc char(20), desc2 char(20) ) ;
Temporary table created.
insert into tp01 values ( "tst""1", "tst'");
1 row(s) inserted.
insert into tp01 values ( 'tst''1', 'tst"');
1 row(s) inserted.
select * from tp01;
desc desc2
tst"1 tst'
tst'1 tst"
2 row(s) retrieved.

Resources