Dynamic Query with MATCHES in Progress 4GL - openedge

I have to create a query in which people can input some values or not. If they don't input them, the program will search for everything. And people can put just a part of the data of the code. My code became something like this.
cQuery = "" +
" FOR EACH table1 " +
" WHERE table1.status_ = 1 " +
" AND table1.section MATCHES " + QUOTER("*"+ pc-section + "*").
So my question.
1 - I read a lot that MATCHES uses a table scan and we should avoid it so I thought about putting MATCHES in an if variable. Is it really necessary?
2 - is the QUOTER(""+ pc-section + "") the correct way of using MATCHES in a dynamic query? My results seem wrong and I don't know if it was because of the MATCHES or if there is another problem in my code.
Sorry for any wrong ideas and thanks for your time.
EDIT:
My IF statement is like this:
DEF VAR ifSection AS CHAR.
IF pc-section <> "" THEN ifSection = " AND table1.section MATCHES " + QUOTER("*"+ pc-section + "*").
And in my code i use:
" FOR EACH table1 " +
" WHERE table1.status_ = 1 " + ifSection.
I managed to make it work now. The problem in my results was because I forgot to add 'ifSection' after THEN. But I still am not sure if this is the best way to do it. Is there another better way to use MATCHES in a dynamic query? Thanks for the help

Don't use IF statements in a WHERE clause - you will never, ever use an index that way.
You can put the IF around the outside:
cQuery = " FOR EACH table1 WHERE table1.status_ = 1 ".
IF <something> THEN
// no index
cQuery = cQuery + " AND field-name MATCHES " + QUOTER("*"+ pc-section + "*").
ELSE
IF <something-else> THEN
// may be indexed
cQuery = cQuery + " AND field-name BEGINS " + QUOTER(pc-section).
ELSE
IF <something-else> THEN
// may be indexed
cQuery = cQuery + " AND field-name = " + input-value.
etc, which will help you at least try to use indexes where possible.
Replacing MATCHES with indexed searching is more complex. You could look at word indexes and the CONTAINS keyword as a start.

Related

Can you ignore a value in a DLL?

In Grrr.Premium.Google.GoogleGeoCode, the baseUrl is set to http://maps.googleapis.com/maps/api/geocode/, which is failing because it needs to be https.
Is it possible to modify the code below to ignore the value in the DLL and define it here?
Grrr.Premium.Google.GoogleGeoCode encode = new Grrr.Premium.Google.GoogleGeoCode();
encode.Query = "json?key=#######&address=" + Server.UrlEncode(txtAddress.Text.Trim() + " " + txtCity.Text.Trim() + " " + drpState.SelectedValue + " " + txtZip.Text);
encode.GeoCode();
I feel like this must be possible, and easy, but I can't figure it out. :(
Thanks in advance for any help.

PadLeft with spaces

Have a relatively simple request.
I wish to pad left a string with spaces in an HTML page using VB on asp.net
For me the most obvious way to do it is
Response.Write(qty.PadLeft(5, " ") + " x " + part_number)
but as HTML does not render multiple spaces, this does not work
my workaround is
Response.Write(qty.PadLeft(5, "0") + " x " + part_number)
which pads the number with zero's but looks fairly unappealing on the website.
Any suggestions?
Thanks
Update:
Based on replies so far I have tried
"100".PadLeft(5, " ")
but this outputs &&100
OK, I solved it by doing this
rep = string.concat(Enumerable.Repeat(" ", 5-qty.Length))
Response.Write(rep + qty+ " x " + part_number)
Not the best but works.
There's & nbsp; or setting or the css (with white-space) to see spaces. If you want to align information, you might want to also look at having a fixed font.

Replacing a new line character with streamwriter remove everything after it. (ASP.NET, Json, C#)

I'm having an unexpected problem which I'm hoping one of you can help me with.
I have an ASP.NET Web API with a number of end points, one of which takes user input, received as JSON, and converts it into an order object which is written to a file in .CSV format. The following is a small snippet of the full code as an example.
using (StreamWriter writer = new StreamWriter(file))
{
writer.Write(escape + order.Notes + escape + delim);
writer.Write(escape + order.Reference1 + escape + delim);
writer.Write(escape + order.Reference2 + escape + delim);
writer.WriteLine();
writer.Flush();
}
The problem I am having is that some users are inclined to add line breaks in
certain fields, and this is causing havoc with my order file. In order to remove
these new line characters, I have tried both of the following methods.
writer.Write(escape + product.Notes.Replace("\n", " ") + escape + delim);
writer.Write(escape + product.Notes.Replace(System.Environment.NewLine, " ") + escape + delim);
However, it seems that, rather than just remove the new line character and carry on writing the rest of the fields, when a new line is encountered, nothing else gets written.
Either everything else gets replace with the " " or nothing else is being written at all, but I'm not sure which.
If I remove the .Replace() the whole file is written again but with extra line breaks.
I hope somebody has experienced this one and knows the answer!

Webmatrix - formatting MSSQL database query

I am trying to format the output of a query in a WebMatrix 2 CSHTML file. This is the code I am using:
#foreach(var row in db.Query(selectQueryString))
{
#row.Firstname; + " " + #row.lastname; + " " + #row.Entry;
}
I am getting this error:
"CS0201: Only assignment, call, increment, decrement, and new object expressions can be used as a statement"
The first issue is that the semicolons could be confusing to Razor, and they are only confusing matters. So change the line in the brackets to
<text>#row.Firstname #row.lastname #row.Entry</text>
And see if that works. The < text > tags tells Razor to output this directly as HTML and not use it as code. You don't need the + " " because once you're putting out HTML, the spaces come automatically.

Filter the results not replace them?

I am working on a google Map Api using fusion. I have multiple search queries and want them to filter the results. At the moment they overrule each other and don't work together the filter the results. The site is called earthquakedamagemap.com. It is my university project. Any help would be much appreciated.
I think it is the 'value.replace' attribute which needs changing?
function changeMap2() {
var searchString = document.getElementById('search-string2').value.replace(/'/g, "\\'");
if(!searchString) {
layer.setQuery("SELECT 'Latitude' FROM " + tableid);
return;
}
layer.setQuery("SELECT 'Latitude' FROM " + tableid + " WHERE 'Updated Risk Assessment:' = '" + searchString + "'");
}
I posted some example code:
in this post not too long ago. You need to combine your search conditions with AND and call layer.setQuery with multiple search conditions only once. I don't think it has anything to do with your replace call as I didn't see any embedded single quotes in your input values.
Eric

Resources