how to show more than one result on query - mysql

I have a procedure on MySQL that returns two results and I need to show this on Delphi but I didn't find how to pass for each result.
Here is how appear on DBForge when I execute, I want this on delphi too, show Query1 and Query2 in a TTabControl.
How to go through this queries and get the name of the query like: Query1,Query2?

You don't say what DB interface lib you're using, like FireDAC, Zeos, or something else.
You're going to issue something like a dbxyz.ExecSQL() call and check for some results.
It sounds like you're expecting to get back multiple records in the result set. Using a TTabControl, you'd simply create a list of tabs like "Result-1", "Result-2", and so on, depending on how many records you get back. (They're results, not queries.) You could select the first one by default.
When another tab is clicked, use the control's TabIndex property to select the corresponding result from the result set, then format up the data in that result and display it in whatever format you're using below the tabs.
There's so little detail you've given that it's impossible to show any code for anything other than the tab control's OnChange handler that will use the TabIndex property to find the desired result set. But this is the overall approach I'd take for this using the TTabControl.

I solve the problem with the command
var
tab: TTabItem;
stringGrid: TStringGrid;
repeat
tab:= TTabItem.Create(nil);
tab.Parent:= tabcontrol1;
tab.Text:= query.Fields.Fields[0].FieldName; //the table name
stringGrid:= TStringGrid.Create(Self);
stringGrid.Parent:= tab;
stringGrid.Align:= TAlignLayout.Client;
for I := 1 to query.FieldCount-1 do
begin
stringGrid.AddObject(TStringColumn.Create(stringGrid));
stringGrid.Columns[i-1].Header:= query.Fields.Fields[i].FieldName;
query.First;
for j := 0 to query.RecordCount-1 do
begin
stringGrid.cells[i-1, j]:= query.Fields.Fields[i].value;
query.Next;
end;
end;
stringGrid.RowCount:= j;
until not query.openNext;

Related

lua, iterating and calling all same-named-functions of n=3 tiers of tables

Say I have multiple tables in {game} like {bullets}, where {bullets} has multiple tables as found below. How would I iterate through and call all the update functions contained in {game}?
--Below is a simplified example, Assume each table in {bullets} has multiple entries not just update. And that the final code must work in cases like game={bullets,coins,whatever}, each entry being of similar nature to bullets.
game={}
game.bullets={{update=function(self) end,...}, {update=function(self) end,...},...}
for obj in all(game) do
for things in all(obj) do
things:update() end end
--I'm not sure what I"m doing wrong and whether I even need a double for-loop.
--if bullets wasn't embedded in {game} it would just be:
for obj in all(bullets) do
obj:update()
end
I've also tried:
for obj in all(game.bullets) do
obj:update()
end
*correction: this works, the problem I want solved though is to make this work if I have multiple tables like {bullets} in {game}. Thus the first attempt at double iterations which failed. So rather than repeat the above as many times as I have items in {game}, I want to type a single statement.
all() isn't a standard function in Lua. Is that a helper function you found somewhere?
Hard to tell without seeing more examples, or documentation showing how it's used, with expected return values. Seems to be an iterator, similar in nature to pairs(). Possibly something like this:
for key, value in pairs( game ) do
for obj in all( value ) do
obj :update()
end
end

Gerrit REST API: cannot use _sortkey to resume a query

I'm using Gerrit REST API to query all changes whose status is "merged". My query is
https://android-review.googlesource.com/changes/?q=status:merged&n=2
where "n=2" limits the size of query results to 2. So I got a JSON object like:
Of course there are more results. According to the REST document:
If the n query parameter is supplied and additional changes exist that match the query beyond the end, the last change object has a _more_changes: true JSON field set. Callers can resume a query with the N query parameter, supplying the last change’s _sortkey field as the value.
So I add the query parameter N with the _sortkey of the last change 100309. The new query is:
https://android-review.googlesource.com/changes/?q=status:merged&n=2&N=002e4203000187d5
With this new query, I was hoping that I'll get another 2 new query results, since I provided the _sortkey as a cursor of my previous search results.
However, it's really weird that this new query returns exactly the same results as the previous query, instead of the next 2 results as I expected. It seems like providing "N=002e4203000187d5" has no effect at all.
Does anybody know why using _sortkey to resume my query doesn't work?
I chatted with one of the developers at Google, and he confirmed that _sortkey has been removed from the newer versions of Gerrit they are running at android-review and gerrit-review. The N= parameter is no longer valid. The documentation will be updated to reflect this.
The alternative is to use &S=x to skip x results, which I tested and works well.
sortkey is deprecated in Gerrit v2.9 -
see the (Gerrit) ReleaseNotes-2.9.txt, under REST API - Changes:
[[sortkey-deprecation]]
Results returned by the [query changes] endpoint are now paginated using offsets instead of sortkeys.
The sortkey and sortkey_prev parameters on the endpoint are deprecated.
The results are now paginated using the --limit (-n) option to limit the number of results, and the -S option to set the start point.
Queries with sortkeys are still supported against old index versions, to enable online reindexing while clients have an older JS version.
See also here -
PSA: Removing the "sortkey" field from the gerrit-on-borg query interface:
...
Our solution is to kill the sortkey field and its related search operators (sortkey_before, sortkey_after, and resume_sortkey).
There are two ways you can achieve similar functionality.
Add "&S=" to your query to skip a fixed number of results.
(Note that this redoes the search so new results may have jumped ahead and
you might process the same change twice.
This is true of the resume_sortkey implementation as well,
so your code should already be able to handle this.)
Use the before/after operators.
Instead of taking the sortkey field from the last returned change and
using it in a resume_sortkey operator, you take the updated field from
the last returned change and use it in a before operator.
(This has slightly different semantics than the sortkey field, which
uses the change number as a tiebreaker when changes have similar updated times.)
...

how to use async.series in middle of for loop

I am trying to find a way to ensure my database query is ran as part of the for loop shown below. I don't know if async.series is the best way, or if fibers might work? Rather than paste loads of code, in pseudo code it looks like this:
for length of array
newArray = array.split
databaseQuery(select **** from *** where x = newArray[0] and y = newArray[1]
my problem is as node is asynchronous, it simply repeats the for loop split while the query is running and then gets the result of the query, meaning I only get the last result returned.
Is there a way to ensure the database query is executed each time in the for loop? I've used nested queries, and callbacks in the past but I can't seem to figure out the best way to call the query each time for the loop

Why is the BSON Null?

Why is it that when I try and do something very similar to the TMongoWire demo program to load a document, I get a different result? On create of a page, I want to get all the company names and load them (eventually) into a combobox. This is the code I am playing with:
d:=BSON;
q:=TMongoWireQuery.Create(MongoWire);
try
q.Query('mwx1.companies',nil);
while q.Next(d) do
begin
s := BsonToJson(d);
sl.add(d['CompanyName']);
sl.Add(TBSONDocument(d).item['CompanyName'])
end;
finally
q.Free;
end;
At the point where I am assigning the JSON to S, the JSON is fully correct and the CompanyName has data in it. That line was there for testing only. But the next two lines both produce nothing (tried various ways to get the data) because it says that the value is null. If I inspect TBSONDocument(d) it shows all the correct information. So I am baffled as to why it isn't working. Any clues?
It starts out as an empty BSON, but when it's in the loop for the first iteration it contains the BSON of
'{"_id":"ObjectID(\"524547512dcf91c1dc7476cb\")","Email":"2324","CompanyName":"T‌​est 1","Addr1":"fs","Addr2":"ertert","City":"iukuiuiku","State":"uikuiku","Zip":"dsf‌​","Country":"ff","Phone":"fdsd","SalesPerson":"sds","ContactPhone":"sdf","Contact‌​Email":"fsdf","ContactName":"f","DateCreated":"g2","website":"34","SMS":"23","Log‌​o":"23423","Status":"qwqw","Keywords":"3423","Shortcode":"qwqw","ParentID":"asda"‌​}'

Show MessageBox if no records for report

I already asked a Question Here.
My this question is just a step ahead to same problem.
I have a delphi code which works perfectly for calling report.
But, now I wanted to show a MessageBox before opening rpt file.
I tried to query it separately for record count and then decide for MessageBox. But, this solution is having a worst case where a aprticular report's query itself takes 3 mins to execute and then again querying while opening rpt it takes 30 sec to load (in second query it takes less time may be because of some data may present in buffer/temp place,etc.).
qPODPhy.close;
qPODPhy.SQL.clear;
qPODPhy.SQL.text :='select * from ViewName';
qPODPhy.Open;
If qPODPhy.RecordCount < 1 Then
MessageBOx('No data To Display...');
Else
Begin
crRep.Somproperties := Initialization
.
.
.
CrRep.SQLQuery := qPODPhy.SQL.text;
crRep.action := 1
End
My Question is :
How can I show a MessageBox if no record is going to present for particular view's output.
OR
Is there a method where I can open the dataset of .rpt file in delphi code and just check the count of records and make the decision? In short, is there some property of crystalreport component which can do this?
You can do a select count(*) separately, that is much faster.
Or maybe select only one record: SELECT TOP 1 ....
And, as RBA suggested, you can try putting that SELECT COUNT in a stored procedure for even more speed.
Just experiments with these methods to see if/when you've gained enough speed.
Are you pushing the data ? You can probably use ReadRecords method of the ReportDocument and check Rows.Count property. If the report is retrieving the data the you can use the NoData event of ReportDocument.