I found the "OnQueryStatement" method :
procedure TkbmMWQueryService2.kbmMWQueryServiceQueryStatement(Sender: TObject;
Place: TkbmMWQueryOperationType; var NamedQueryName, Statement: string);
begin
Form1.Memo1.Lines.Add(Statement);//show the query statement
end;
this method can get the client-side query statement,but all the client-side query trigger this event twince!(like the screenshot)!Why? How can i get the client-siade query statement correctly?
thanks in advance! :)
Its called twice on the server (in fact can be called 3 times for the same query on the server in the most far out situation).
Check the Place argument for the situation that its called in.
It can be
mwqotDefinition,mwqotQuery,mwqotExecute,mwqotResolve,mwqotMoreData,mwqotMetaData
The reason its being called multiple times when opening the query, is that the dataset first likes to get the definition (which fields and parameters will this query result in), and then the data itself.
Both the server and the client default operates like that. Hence opening a query on the client result the client in asking the server about definitions, then the client asks for the data, and that on the server may result in the server itself asking for definitions and then the data. Remember the server is stateless and default doesnt know anything about previous calls to it.
There are many ways to optimize this:
Enable caching for metadata (definitions). That will result in the cache results being used instead of the server asking the database for the definitions, and enabling the cache on the client too, results in the client not having to ask the server for definitions except first time.
Setup the AutoFieldDefs property on the query to mwafoWithData. Then the data will actually be returned at the same time as the definitions, and the 2.nd data fetch call will be skipped.
Related
I'm struggling to work out how to retrieve the property values from a filter query in a CosmosDb stored procedure. I'm sure this must be relatively simple, but just can't seem to find the right combination.
var result = __.chain()
.filter(function(doc) {
return doc.id ==="1stDocId";
})
.map(function(doc) {
return {
id: doc.id,
propertyA: doc.propertyA
};
})
.value();
if(!result.isAccepted) throw new Error("The call was not accepted");
Using the above code, or similar, I'm wanting to retrieve the value of propertyA, and then use it in a second query, and so on.
Using response.setBody to return the value of result at this point, I can see it is sat in an array, but can't work out the correct code to access it.
result[0].PropertyA, result[0][0].PropertyA don't work, can someone point me in the right direction?
I'm able to do this sort of thing using the queryDocuments function, but ultimately my stored procedure needs to execute 5 or 6 select statements, manipulating the retrieved values in between. Utilising nested callbacks seems very messy, and pretty confusing once you're a few levels deep. Is there a better way?
Thanks.
Well I gave in, and wrote the procedure using nested callbacks and 'queryDocuments'. Since at one point my procedure requires a switch statement, which either performs a db lookup, or provides a hard value, I had to duplicate the rest of the queryDocument calls in the db lookup branch callback, which feels plain wrong.
However, whilst not being pretty, my stored procedure now works, returning the correct values in all cases.
When doing a PurchaseOrderQuery in QBXML I am trying to get Quickbooks to only return purchase orders that are not yet processed (i.e. "IsFullyReceived" == false). The response object contains the IsFullyReceived flag, but the query object doesn't seem to have a filter for it??
This means I have to get every single Purchase Order whether or not it's received, then do the filtering logic in my application - which slows down Web Connector transactions.
Any ideas?
Thanks!
You can't.
The response object contains the IsFullyReceived flag, but the query object doesn't seem to have a filter for it??
Correct, there is no filter for it.
You can see this in the docs:
https://developer-static.intuit.com/qbSDK-current/Common/newOSR/index.html
This means I have to get every single Purchase Order whether or not it's received, then do the filtering logic in my application - which slows down Web Connector transactions.
Yep, probably.
Any ideas?
Try querying for only Purchase Orders changed or modified (ModifiedDateRangeFilter) since the last time you synced.
Or, instead of pulling every single PO, keep track of a list of POs that you think may not have been received yet, and then only query for those specific POs based on RefNumber.
Or, watch the ItemReceipt and BillPayment objects, and use that to implement logic about which POs may have been recently filled, since BillPayment andItemReceipt` objects should get created as the PO is fulfilled/received.
I've not been able to find an answer on this anywhere. Using Delphi XE7 with TClientDataSet, DataSnap & SQL Server. I need to insert a record, apply updates and then refresh that record so I can get the Id and assign it to my object. Seems pretty basic requirement, but on the contrary it is proving to be a royal pain.
I've found the obvious stuff on EDN, SO and Dr Bob:
http://edn.embarcadero.com/article/20847
DataSnap and the autoinc field
http://www.drbob42.com/examines/examinC0.htm
However these seem to focus on a "Refresh" of the TClientDataSet to re-fetches the entire table/query. Whilst this does actually resolve the Id field itself (good!), it also moves the cursor off the current record which was just inserted and so I'm not able to get the Id and assign it to my object. Also, for performance over HTTP I don't really want to refetch the entire table every time a record is inserted, if there's 10,000 records this will consume too much bandwidth and be ridiculously slow!
Consider the following code:
function TRepository<I>.Insert(const AEntity: I): I;
begin
FDataSet.DisableControls;
try
FDataSet.Insert;
AssignEntityToDataSet(AEntity); // SET'S ALL THE RELEVANT FIELDS
FDataSet.Post;
FDataSet.ApplyUpdates(-1);
FDataSet.Refresh; // <--- I tried RefreshRecord here but it cannot resolve the record
AEntity.Id := FDataSet.FieldByName('Id').AsInteger; // <----- THIS NOW POINTS TO WRONG ROW
finally
FDataSet.EnableControls;
end;
end;
Does anyone know how to achieve this? I need to be able to refresh and stay on the current record otherwise I do not know the Id of the record just created and the GUI cannot stay focused on the current record.
Hopefully something obvious I'm missing.
Cheers.
Rick.
Assuming you can get hands on the new ID inside the AfterUpdateRecord event of your DataProvider, your event handler then may look like this (the current record of DeltaDS is the one just inserted into SourceDS):
if (UpdateKind = ukInsert) then begin
DeltaDS.FindField('Id').NewValue := <TheNewID>;
end;
Make sure to have the poPropogateChanges option set in the provider. This will transfer the changed Id field back to the ClientDataSet.
Now you can get rid of the FDataSet.Refresh call.
SQL Server does allow you to get the last identity it generated in several ways - there's no need to "refresh" the record/query which means re-issuing a SELECT and can generate undesiderable side-effects. You can use SELECT SCOPE_IDENTITY() or use an OUTPUT clause. If the Delphi database driver supports it, TField.AutogenerateValue should accomplish that task automatically (see http://docwiki.embarcadero.com/Libraries/XE7/en/Data.DB.TField.AutoGenerateValue)
Otherwise you have to put that new data into your delta (see Raabe answer - this has to be done on the datasnap server which actually talks to the database) after reading it, so it's sent back to the client. You also need to set properly and TField.ProviderFlags to ensure data are applied correctly (see http://docwiki.embarcadero.com/RADStudio/XE7/en/Influencing_How_Updates_Are_Applied), usually you don't want those field appear in an UPDATE.
I am using EF code first model to get the data from data base table in which i have 400,000 records.
But when i use the LINQ query something like:
var urer = context.UserEntity.Where(c => c.FirstName.Contains('s'));
The above statement gives me all the user to whose first name contains 's'. But since this is a huge data base table, it is giving me the following error:
An existing connection was forcibly closed by the remote host
Please suggest me the best way to do it. I am assigning this data to gridview. I am thinking to get the first 500 each time. Is there any way to do it from EF side, so that i won't need to do it in sql.
Thanks
1.add index on your column
2. increase timeout connection
You can create Store procedure
USE LINQ call Store procedure
LINQ to SQL (Part 6 - Retrieving Data Using Stored Procedures)
http://weblogs.asp.net/scottgu/archive/2007/08/16/linq-to-sql-part-6-retrieving-data-using-stored-procedures.aspx
See this answer as well
Calling a SQL Server stored procedure with linq service through c#
Get rid of EF
set key in web.config common key for timeout replace 600
try
{
conn.Open();
mySqlCommand.Connection = conn;
mySqlCommand.CommandTimeout=600;
I have a simple SOAP apllication:
Middle Tier: TSOAPDataModule including TDatasetProvider linked to TADOQuery. TADOQuery has defined a few Parameters (different datatypes)
Client: TClientDataSet linked to TSOAPConnection and provider set to DatasetProvider in MiddleTier.
In design time i can succesfully Fetch Params and Fields for the ClientDataSet from Server. In runtime I programaticaly set parameters for the ClientDataSet and call Open. But I get an SQL error (comming from SQL Server, through ADOQuery in Middle Tier, passed by SOAP to the client) about incorrect values in parameters. After detail debugging I found that the parameters are correctly passed from client to the SOAP server. The Provider.Params lists all the parameters correctly. Unfortunatelly before the ADOQuery opens (after the ADOQuery.Parameters are assigned from the DataSetProvider) the DataType of all the parameters are changed. ie.: original ADOQuery Parameter DataType was ftDateTime but after assignment from DataSetProvider it becomes ftWideString.
This happens for any Parameter DataType that is not null from the Client - all of them become ftWideString.
I have found that this change happens in TParam.Assign where TParameter(Destination).Value is assigned before TParameter(Destination).DataType. After the Value is assigned the DataType is automatically guessed from the varType of the Value. As the Value comes from OleVariant it is always considered to be String.
I tried to alter the TParam.Assign procedure = Assign DataType before Value. But in this way I get ADO Error of Value type being incompatible with DataType.
I think that the problem is in the way tha parameters are being encoded into SOAP XML request. Their values are simply '{value}' without any type information.
I've googled a lot for this problem, but didn't find even a note of simmillar behaviour.
Do I do something wrong, or is this a bug in SOAP in Delphi?
PS: I run Delphi 2009
EDIT:
I just found a sample SOAP request that has the params marshaled in the following structure:
<NS1:V NS2:VarArrayType="8204">
<V xsi:type="xsd:string">param1</V>
<V xsi:type="xsd:string">Frank</V>
<V xsi:type="xsd:byte">1</V>
<V xsi:type="xsd:byte">1</V>
</NS1:V>
The same in my case looks this way:
<NS1:V NS2:VarArrayType="8204">
<V>param1</V>
<V>Frank</V>
<V>1</V>
<V>1</V>
</NS1:V>
I think this is the root of my troubles but do not know how to make my client to add xsi:type attribuge to the SOAP request.
I found it. I have registered my SOAPDataModule with
InvRegistry.RegisterInterface(TypeInfo(IMyIntf), MyNamespace, 'UTF-8');
InvRegistry.RegisterInvokeOptions(TypeInfo(IMyIntf), [ioDocument, ioHasNamespace, ioIsAppServerSOAP]);
Including ioDocument in RegisterInvokeOptions made the xsi:type attribute not to be included in Variant type data. This made unmarshaling the param values to olestring types. So the solution for my problem is:
InvRegistry.RegisterInvokeOptions(TypeInfo(IMyIntf), [ioHasNamespace, ioIsAppServerSOAP]);