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

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.

Related

varaible value has apostrophe ACCESS VBA

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)'

Google Sheet: Using drop-down and check-boxes (data type: text & True/False) to filter data

firstly thanks in advance.
Before posting this, I’ve searched and tried a few guides from several sources. However, was to no success in constructing formula string. Filtering data in Google sheet (GS) using Query + other functions is something new to me and I’m still learning.
Goal:
Use drop-down and 2 types of check-boxes (data type: text & True/False). User can select one or more checkboxes to filter data.
Problem:
Was not successful to construct formula string to combine drop-down & check-boxes
My GS example was taken from one of the solution which used a simple formula string for check-boxes (data type: True/False) to create filter and hoping I could developed from it.
My Google sheet link
Thanks again!
This seems to do what you've asked for. Try the following formula in E6 of your results sheet. Or see my tab Answer-GK, which I added to your sheet.
=iferror(if(or(C5:C13),
QUERY ('Test string DB'!A3:H12, "Select * WHERE " &
IF(B2="","C <>'' "," C = '"&B2&"'") &
IF(C5, " and D matches '" & B5 & "' ",) &
IF(C6, " and D matches '" & B6 & "' ",) &
IF(C7, " and D matches '" & B7 & "' ",) &
IF(C8, " and E matches '" & B8 & "' ",) &
IF(C9, " and E matches '" & B9 & "' ",) &
IF(C10, " and E matches '" & B10 & "' ",) &
IF(C11, " and F=TRUE", ) &
IF(C12, " and G=TRUE", ) &
IF(C13, " and H=TRUE", )),
QUERY ('Test string DB'!A3:H12,"select * " & if(B2=""," "," where C = '"&B2&"'") ,0)),
"No results - Reduce your selected criteria")
Something to note. Since some of your data elementss have dedicated columns, and others are shared columns, it limits what you can filter. For example, you can't find a campsite that has a beach AND a lake, since your data only allows you to have one or the other element.
The same for access - it can't be both walking and 4WD. So if you check two or more tickboxes, for either Features or Accessible By, you get no results. You don't have this issue with Ammenities, since you have a separate column (data element) for each of shower, toilet, and plugpoint. I hope this makes sense, I assume that you may want to expand your data structure to allow multiple elements, as you have for Amenities. The formula would need to be modified in that case.
But otherwise I think it is working as you intended.
Let us know of any issues with this.
UPDATE:
To perhaps improve the appearance, I modified The "TRUE" values to show as "Y", using hidden columns in J to L, and the following formula in M5. There are also other ways of doing this.
={"Toilet","Shower","Plugpoint";
arrayformula(if(J6:L,"Y",""))}
This adds the three header labels, then looks through columns J,K,L for TRUE values, and returns them as "Y"s.
I am assuming you intended the the Feature and Accessible check boxes to be inclusive and the Amenities to be exclusive. Here is a working example:
https://docs.google.com/spreadsheets/d/1AqQCKRrhTzJyLWldcpeFAv1o4sLvphv3F52VCgpa4rE/edit?usp=sharing
Here is the formula in E6:
=iferror(QUERY(QUERY('Teststring DB'!A3:H12,"select * where C = """&B2&""" AND (D = """& if(C5 = true,B5,"")&""" OR D = """& if(C6 = true,B6,"")&""" OR D = """& if(C7 = true,B7,"")&""") OR (E = """& if(C8 = true,B8,"")&""" OR E = """& if(C9 = true,B9,"")&""" OR E = """& if(C10 = true,B10,"")&""") ",0),"select * " & if(C11 = true,"where Col6 = true","")&" " & if(C12 = true,if(C11 = true,"AND Col7 = true","where Col7 = true"),"")&" " & if(C13 = true,if(or(C11 = true,C12 = true),"AND Col8 = true","where Col8 = true"),"")&" ",0),QUERY('Teststring DB'!A3:H12))

I want to conditionally prefix autonumber or number filed in ms-access

Fields
[Group] (values are ARTS , PRE-MED , PRE-ENG, ICS )
i want data on new field called RollNo something like 18AR01"
only 2 last digits of current year + iif([group]=ARTS,AR,iif([group]=PRE-MED,PM,iif([group]=PRE-ENG,PE,iif([group]=ICS,NULL,))))
how this can be possible ?
You can use the BeforeInsert event of the form:
Dim Code As String
Dim Number As Integer
Code = Nz(Format(Date, "yy") & Switch(Me![Group] = "ARTS", "AR", Me![Group]= "PRE-MED", "PM", Me![Group] = "PRE-ENG", "PE"))
Number = Val(Nz(DMax("Right([RollNo], 2)", "YourTable", "[RollNo] Like '" & Code & "??'"))) + 1
Me!RollNo.Value = Format(Date, "yy") & Code & Format(Number, "00")

FireDAC Query connect to DBGrid

I have FDQuery and DataSource and DBGrid. Now I write this code in Button
FDQuery2->Active = false;
FDQuery2->SQL->Clear();
FDQuery2->SQL->Add(" SELECT C.patient_id, P.patient_name, C.check_id "
" FROM Checkup C "
" INNER JOIN Patient P ON (C.patient_id=P.patient_id) "
" WHERE C.today = " + MaskEdit1->Text +
" ORDER BY C.check_id ");
FDQuery2->Active = true;
and i connect FDQuery to DataSource and tDataSource to DBGrid, but when I click the Button it doesn't show rows. and i am sure that SQL code is work, because when i write inside the SQL String the rows have been shown.
any ideas.
You're missing the ' around your value when concatenating the text. Change your WHERE clause:
FDQuery2->SQL->Clear();
FDQuery2->SQL->Add(" SELECT C.patient_id, P.patient_name, C.check_id "
" FROM Checkup C "
" INNER JOIN Patient P ON (C.patient_id=P.patient_id) "
" WHERE C.today = '" + MaskEdit1->Text + "'" +
" ORDER BY C.check_id ");
You really should learn to use parameterized queries instead, though. It allows the database driver to handle things like properly quoting text or formatting dates for you, and it also (importantly) prevents SQL injection.
FDQuery2->SQL->Clear();
FDQuery2->SQL->Add(" SELECT C.patient_id, P.patient_name, C.check_id "
" FROM Checkup C "
" INNER JOIN Patient P ON (C.patient_id=P.patient_id) "
" WHERE C.today = :today" +
" ORDER BY C.check_id ");
FDQuery2->ParamByName("today")->AsString = MaskEdit1.Text;
FDQuery2->Active = true;

return array in lua from a sqlite database

How do you return an array from a sqlite database in lua?
I have this sameple code here:
function getMoveName()
tempMoveName = {}
for row in db:nrows("SELECT * FROM movetable") do
tempMoveName = row.movename .. " " .. row.totalcubicfeet .. " " .. row.totalitem .. "\n"
end
return tempMoveName
end
which will return the content of the database and then print the content with this line of code:
local displaymovenames = mydatabase.getMoveName()
print ( displaymovenames )
however it only returns the last data and not all of the contents of it.
What you are doing is for every row, you just store the row data in the variable tempMoveName and hence overwriting the previous value.
You need to add the rowData to the table tempMoveName.
function getMoveName()
tempMoveName = {}
for row in db:nrows("SELECT * FROM movetable") do
local rowData = row.movename .. " " .. row.totalcubicfeet.." "..row.totalitem.."\n"
tempMoveName[#tempMoveName+1] = rowData
end
return tempMoveName
end
EDIT
To access the table elements you have to do the following
for i=1,#tempMoveName do
print(tempMoveName[i])
end
note that #tempMoveName gives the length of the table(i.e no. of elements in the table)
P.S if you are going to do a lot of coding in Lua, I'd suggest you get a grip on the basics of Tables, cos table is the main datatype of Lua. Arrays, lists, dictionaries, classes and almost everything are implemented via tables. Here is a tutorial for a start!
This has nothing to do with SQL or databases; this is basic Lua stuff here.
This:
tempMoveName = {}
creates a table and stores the table into the (global) variable named tempMoveName.
This:
tempMoveName = row.movename .. " " .. row.totalcubicfeet .. " " .. row.totalitem .. "\n"
Creates a big string from concatenating other strings (don't forget about string.format) and stores that in the (global) variable named tempMoveName.
Note what I said: "stores it in the variable". Not "in the table stored in the variable".
It's no different from doing this:
tempMoveName = 1
tempMoveName = "foo"
This doesn't combine a string with an integer in some way. tempMoveName held 1, then it was replaced with "foo".
Tables aren't special; they're values just like anything else in Lua. Variables hold values. So if you change which value is stored in a variable, you have changed which value is stored there. You haven't affected the value itself, only where it is stored.
If you have a table stored in a variable, and you want to build an array, you should access the elements within the table, not the variable itself. This is done in the usual way:
tempMoveName[#tempMoveName + 1] = row.movename .. " " .. row.totalcubicfeet .. " " .. row.totalitem .. "\n"
Alternatively, you can use table.insert:
table.insert(tempMoveName, row.movename .. " " .. row.totalcubicfeet .. " " .. row.totalitem .. "\n")
Lastly, if tempMoveName is meant to be temporary (as the name suggests), then you should declare it as a local variable.

Resources