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.
Related
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.
I need to query a stored procedure and on the basis of result set of that procedure need to make decisions in conditional statement
For instance I have a stored Procedure "Main_SP"
Now if result of "Main_SP" is 'null' then the result should be 'Tweety', but if th result set is not null then result set should be retrieved,
how to do it?
I tried following and some other but none worked.
SELECT
case Main_SP('MyVariable')
when 'null'
then 'Tweety' end
FROM SYSIBM.SYSDUMMY1 WITH UR
SELECT
case Main_SP('MyVariable')
when null
then 'Tweety' end
FROM SYSIBM.SYSDUMMY1 WITH UR
It is failing the condition, In first command when even it is 'null' it is not printing 'Tweety'.
and while using second, Getting error that 'Null' is not valid in the context.
I don't believe you can use a stored procedure that way.
A stored procedure can return data in two ways
As a result set
in an output or input/output parm
You're not using option 2 and I don't think a result set is ever NULL. There might be no records, but the RS itself isn't NULL. In addition, from what I can see in the manuals, processing a RS from a stored proc inside another stored proc in DB2 requires you to declare an allocate result set locators. But I've never done this.
If your procedure returns a single value or null, you'd be better served by defining it as a function with a return value. Then your code would be simply:
SELECT
COALESCE(Main_Fnc('MyVariable'),'Tweety')
FROM
SYSIBM.SYSDUMMY1 WITH UR
You can't call a stored procedure as part of an SQL fullselect; you would need to have the client that calls the stored procedure handle this logic. If you must do it on the server, implement a new stored procedure that calls Main_SP itself and contains your logic to interpret the result.
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]);
I am currently testing with:
A SQLConnection which is pointed towards an IB database.
A SQLDataset that has a SQLConnection field set to the one above.
A DatasetProvider that has the SQLDataset in (2) as its Dataset field value.
A ClientDataset, with the ProviderName field pointing to the provider in (3).
I use the following method (borrowed from Alister Christie) to get the data...
function TForm1.GetCurrEmployee(const IEmployeeID: integer): OleVariant;
const
SQLSELEMP = 'SELECT E.* FROM EMPLOYEE E WHERE E.EMPLOYEEID = %s';
begin
MainDM.SQLDataset1.CommandText := Format(SQLSELEMP, [Edit1.Text]);
Result := MainDM.DataSetProvider1.Data;
end;
Which populates the DBGrid with just one record. However, when I manually edit the record, click on Post, then try to commit the changes, using
MainDM.ClientDataset1.ApplyUpdates(0); // <<<<<<
It bombs, with the message "SQLDataset1: Cannot modify a read-only dataset."
I have checked the ReadOnly property of the Provider, and of the ClientDataset, and the SQL has no joins.
What could be causing the error?
It appears that your ClientDataSet.Data property is being populated from the Data property of the DataSetProvider. With the setup you described, you should be able to simply call ClientDataSet.Open, which will get the data from the DataSetProvider.
BTW, the default behavior of the DataSetProvider when you call the ClientDataSet.ApplyUpdates method is to send a SQL query to the connection object, and not the DataSet from which the data was obtained (assuming a homogeneous query). Make sure that your DataSetProvider.ResolveToDataSet property is not set to true.
Finally, on an unrelated note, your code above appears to be open to a SQL injection attack (though I have not tested this). It is safer to use a parameter to define the WHERE clause. If someone enters the following into Edit1 you might be in trouble (assuming the InterBase uses the drop table syntax): 1;drop table employee;
Check the LiveMode property of the TIBDataSet.