How can we use locate function or a same operation function using a calculated field in delphi Tadotable?
something like this
SampleAdotable.locate('samplefield',text,[lopartialkey]);
where samplefield is a calculated field in SampleAdotable.In normal case an exception with this message is created:
Item can not be found in the collection corresponding to the requested name or ordinal
thank you
If your SampleField is of type fkCalculated, I don't think you can use this field as a field whose value you try to locate in a call to Locate.
The reason is that Locate calls TCustomADODataSet.LocateRecord which generates the error you quote and the reason it does is that SampleField is not a field in the ADO Recordset underlying the TCustomADODataSet. The exception occurs in the call to Cursor.MoveNext.
To do what you want, try constructing a calculated field in the SQL expression used to obtain the row data from the database. Depending on the server you are using, you may need to use a TAdoQuery instead of a TAdoTable to get the rows.
Related
I'm trying to use Delphi 11.2's TFDBatchMove to make a copy of a record in a Firebird database table. The table contains at least one column which is set to "not null" and a default value for the column is specified.
The reader for the TFDBatchMove is a TFDBatchMoveDataSetReader which gets a TFDQuery assigned to .DataSet. That query selects all the columns to copy, which excludes the "not null" column!
The Write for the TFDBatchMove is a TFDBatchMoveSQLWriter, which only gets the DBConnection assigned and the correct TableName.
At runtime I get an exception on .Execute of the TFDBatchMove:
First chance exception at $7720E292. Exception class EIBNativeException with message
'[FireDAC][Phys][FB]validation error for column "MEINE_TABELLE"."MEINE_SPALTE", value "*** null ***"'. Process MeineExe.exe (6728)
How to prevent it trying to write to that column?
I meanwhile found out that the writer has already some event assigned where I can modify the data written based on which column it tries to write to and there I can (and even need to) set a value for that not null colmum which differs from the default specified in the database anyway.
So one can either "close" this question as "resolved" or wonder why the TFDBatchMove seemingly tries to write null into that column, which was not in the select clause of the reader instead of letting the DB use the default value set up.
I have a small Delphi 2009-application that serves as a way to call some SQL procedures and do some background work.
It can be called with a path to a text file containing a SQL statement as input parameter and executes it.
Now I want the Delphi-application to return an output value, a string.
I found how to deal with output values when calling applications from a batch file (How do I get the result of a command in a variable in windows?), but I don't know how to fill this value from within Delphi. Where in Delphi do I assign my string value to some kind of output parameter, so the calling batch file can use the value?
Thanks
Write it to the standard output:
Writeln(MyOutputText);
I am getting capability error whenever I am trying to set active property tue. I want to bind the grid with the stored procedure that takes one parameter.
If I do it through TQuery How do I specify the fields. I am using wwDBGrid.
MessageMembershipSelectQuery.Params[0].AsString :=
custQuery.FieldByName('cust_code').AsString;
MessageMembershipSelectQuery.Active := True;
Please guide
Replace you Query component by a StoredProc component. Also, check your parameter data type. If it is indeed a string parameter, then it´s Ok to use AsString, but if the parameter has a different data type, like Integer, for instance, then you should assign it´s value by using, for instance, AsInteger.
I want to use a dbExpress TSQLQuery component. But i do not know how to write the SQL to add a parameter. I will give an example maybe it will be more clear what my problem is.
In a TADOQuery the following works:
SELECT*
FROM sometable
WHERE sometable.id = :value;
Now in the above example you pass the parameter to the query using the colon (:) before the parameter name. But when I try and do that with the TSQLQuery, I get the following error:
dbExpress driver does not support the TDBXTypes.UNKNOWN data type. Vendor Error Message.
Now if this is not the way that you pass a parameter in a TSQLQuery component, can someone please assist me. This is new territory for me.
Im using a Firebird database, and Im using Delphi XE2
To set the properties of a parameter you must use the Params property. From here you can access each paramer using a index or the name, to set the value of the parameter use one of the properties AsString, AsInteger an so on, depeding of the type of the field.
Check this sample
var
LSQLQuery : TSQLQuery;
begin
LSQLQuery:=TSQLQuery.Create(nil);
try
LSQLQuery.SQLConnection:=SQLConnection1;
LSQLQuery.CommandText:='Select FIRST_NAME from EMPLOYEE Where EMP_NO=:Param1';
LSQLQuery.Params.ParamByName('Param1').AsInteger:=2;//or using the index of the parameter LSQLQuery.Params[0].AsInteger:=2;
LSQLQuery.Open;//Execute the query
ShowMessage(LSQLQuery.FieldByName('FIRST_NAME').AsString); //get the data
LSQLQuery.Close;
finally
LSQLQuery.Free;
end;
end;
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]);