RTC Forums
November 24, 2024, 02:50:48 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   Home   Help Login Register  
Pages: [1]
  Print  
Author Topic: Sending Array of Variant to Server  (Read 4810 times)
Theprasit
RTC License++
*****
Posts: 42


« on: June 18, 2013, 08:49:33 AM »

I tried to send array of variant as remote function parameter using rtcArray but not success., e.g.

Sending -> OpenSql('Exec StoreProc1 :P1, :P2', [2, '300']);

This will call function to execute store procedure (which return record set) on the server side but seem not to work.

So, how to send this kind of data type among client and server?

Regards,
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #1 on: June 18, 2013, 10:08:00 AM »

You can not send "Variant" data types, because "Variant" is not a type. It is a container for a number of different data types. But, you can send your store procedure call parameters in an array or record where each element is of a different type, like ...

Code:
with RtcClientModule.Prepare('OpenSql') do
  begin
  asText['my_sql_statement']:='Exec StoredProc1 :P1, :P2'; // Unicode String
  with newArray('my_parameters') do
    begin
    asInteger[0]:=2; // integer value
    asString[1]:='300'; // 8-bit character String
    end;
  end;

While you could also use the "Value" property, which reads and sets data using the Variant type, I do not recommend it, because type conversions are required ("Variant" can NOT be sent) and you won't know for sure what type your data ended up in.

Best Regards,
Danijel Tkalcec
Logged
Theprasit
RTC License++
*****
Posts: 42


« Reply #2 on: June 18, 2013, 12:14:00 PM »

WOW! very fast response  Cheesy

Per your example, this is fine but in actual requirement, the number of parameters is not fixed, that's why I intended to use open array to pass these parameters.

I did some experiment and managed to resolve it by iterate open array value into rtcArray data type (using .asValue[]).

I awarded with your mentioned about Variant but "OpenSql" is my generic function which receive any type of parameters for SQL statement.

Do you have any ideas beside using .asValue[] ?

Thank you and Regards,
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #3 on: June 18, 2013, 12:36:56 PM »

If you are happy with "asValue", then use it. But I would recommend checking what type is actually being sent and then assigning the value using asInteger, asString, asText, asCardinal, asFloat, asDateTime, ... That's more work, but it ensures that you have covered all the types you need to support and that type conversions are done according to your requirements.

Best Regards,
Danijel Tkalcec
Logged
Theprasit
RTC License++
*****
Posts: 42


« Reply #4 on: June 18, 2013, 01:14:09 PM »

Thank you for your suggestion, will seek for others alternative.

Best Regards,
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.024 seconds with 16 queries.