Class: Advantage::AdvantageInterface

Inherits:
Object
  • Object
show all
Defined in:
ext/advantage/advantage.c

Instance Method Summary collapse

Instance Method Details

#ads_affected_rows(VALUEimp_drh, VALUEads_stmt) ⇒ Object

Returns the number of rows affected by execution of the prepared

statement.

<b>Parameters</b>:
- <tt>VALUE imp_drh</tt> -- An initialized API structure to finalize.
- <tt>VALUE ads_stmt</tt> -- A statement that was prepared and executed successfully with no result set returned.

<b>Returns</b>:
- <tt>VALUE result</tt>: The number of rows affected or <tt>-1</tt> on failure.


1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
# File 'ext/advantage/advantage.c', line 1127

static VALUE
static_AdvantageInterface_ads_affected_rows(VALUE imp_drh, VALUE ads_stmt)
{
   imp_drh_st *s_imp_drh;
   ADSHANDLE s_stmt;
   UNSIGNED32 result;

   Data_Get_Struct(imp_drh, imp_drh_st, s_imp_drh);
   //Data_Get_Struct( ads_stmt, ADSHANDLE, s_ads_stmt );
   s_stmt = (ADSHANDLE)NUM2ULL(ads_stmt);

   result = s_imp_drh->api.ads_affected_rows(s_stmt);

   return (INT2FIX(result));
}

#ads_bind_param(VALUEimp_drh, VALUEads_stmt, VALUEindex, VALUEads_bind_param) ⇒ Object

Binds a user supplied buffer as a parameter to the prepared statement.

<b>Parameters</b>:
- <tt>VALUE imp_drh</tt> -- An initialized API structure to finalize.
- <tt>VALUE ads_stmt</tt> -- A statement object that was returned from ads_prepare(  ).
- <tt>VALUE index</tt> -- The index of the parameter. This should be a number between 0 and ads_num_params(  ) - 1.
- <tt>VALUE ads_bind_param</tt> -- A filled bind object retrieved from ads_describe_bind_param(  ).

<b>Returns</b>:
- <tt>VALUE result</tt>: <tt>1</tt> on success or <tt>0</tt> on failure.


1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
# File 'ext/advantage/advantage.c', line 1213

static VALUE
static_AdvantageInterface_ads_bind_param(VALUE imp_drh, VALUE ads_stmt, VALUE index, VALUE ads_bind_param)
{
   imp_drh_st *s_imp_drh;
   ADSHANDLE s_stmt;
   a_ads_bind_param *s_ads_bind_param;
   UNSIGNED32 result;
   UNSIGNED32 s_index;

   Data_Get_Struct(imp_drh, imp_drh_st, s_imp_drh);
   //Data_Get_Struct( ads_stmt, ADSHANDLE, s_ads_stmt );
   s_stmt = (ADSHANDLE)NUM2ULL(ads_stmt);
   Data_Get_Struct(ads_bind_param, a_ads_bind_param, s_ads_bind_param);
   s_index = NUM2INT(index);

   result = s_imp_drh->api.ads_bind_param(s_stmt, s_index, s_ads_bind_param);

   return (INT2FIX(result));
}

#ads_clear_error(VALUEimp_drh, VALUEads_conn) ⇒ nil

Clears the last stored error code.

<b>Parameters</b>:
- <tt>VALUE imp_drh</tt> -- An initialized API structure to finalize.
- <tt>VALUE ads_conn</tt> -- A connection object that was connected by ads_connect(  ).

<b>Returns</b>:
- <tt>nil</tt>:.

Returns:

  • (nil)


1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
# File 'ext/advantage/advantage.c', line 1431

static VALUE
static_AdvantageInterface_ads_clear_error(VALUE imp_drh, VALUE ads_conn)
{
   imp_drh_st *s_imp_drh;
   a_ads_connection *s_ads_conn;

   Data_Get_Struct(imp_drh, imp_drh_st, s_imp_drh);
   TypedData_Get_Struct(ads_conn, a_ads_connection, &ads_connection_type, s_ads_conn);

   s_imp_drh->api.ads_clear_error(s_ads_conn);

   return (Qnil);
}

#ads_client_version(VALUEimp_drh) ⇒ Array

Retrieves the client version as a string.

This function can be used to retrieve the client version.

<b>Parameters</b>:
- <tt>VALUE imp_drh</tt> --  an initialized API structure to finalize

<b>Returns</b>:
- <tt>VALUE verstr</tt>: The client version string.

Returns:

  • (Array)


364
365
366
367
368
369
370
371
372
373
374
375
# File 'ext/advantage/advantage.c', line 364

static VALUE
static_AdvantageInterface_ads_client_version(VALUE imp_drh)
{
   imp_drh_st *s_imp_drh;
   char s_buffer[255];

   Data_Get_Struct(imp_drh, imp_drh_st, s_imp_drh);

   s_imp_drh->api.ads_client_version((UNSIGNED8 *)s_buffer, 255);

   return (rb_str_new2(s_buffer));
}

#ads_commit(VALUEimp_drh, VALUEads_conn) ⇒ Object

Commits the current transaction.

<b>Parameters</b>:
- <tt>VALUE imp_drh</tt> -- An initialized API structure to finalize.
- <tt>VALUE ads_conn</tt> -- A connection object that was connected by ads_connect(  ).

<b>Returns</b>:
- <tt>VALUE result</tt>: <tt>1</tt> on successful commit, <tt>0</tt> otherwise.


884
885
886
887
888
889
890
891
892
893
894
895
896
897
# File 'ext/advantage/advantage.c', line 884

static VALUE
static_AdvantageInterface_ads_commit(VALUE imp_drh, VALUE ads_conn)
{
   imp_drh_st *s_imp_drh;
   a_ads_connection *s_ads_conn;
   UNSIGNED32 result;

   Data_Get_Struct(imp_drh, imp_drh_st, s_imp_drh);
   TypedData_Get_Struct(ads_conn, a_ads_connection, &ads_connection_type, s_ads_conn);

   result = s_imp_drh->api.ads_commit(s_ads_conn);

   return (INT2FIX(result));
}

#ads_connect(VALUEimp_drh, VALUEads_conn, VALUEstr) ⇒ Object

Creates a connection object.

An API connection object needs to be created before a database connection
is established. Errors can be retrieved from the connection object. Only
one request can be processed on a connection at a time.

<b>Parameters</b>:
- <tt>VALUE imp_drh</tt> -- An initialized API structure to finalize.
- <tt>VALUE ads_conn</tt> -- A connection object that was created by ads_new_connection(  ).
- <tt>VALUE str</tt> -- A connection string.

<b>Returns</b>:
- <tt>VALUE result</tt>: <tt>1</tt> on success, <tt>0</tt> on failure.


396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
# File 'ext/advantage/advantage.c', line 396

static VALUE
static_AdvantageInterface_ads_connect(VALUE imp_drh, VALUE ads_conn, VALUE str)
{
   imp_drh_st *s_imp_drh;
   a_ads_connection *s_ads_conn;
   char *s_str;
   UNSIGNED32 result;

   Data_Get_Struct(imp_drh, imp_drh_st, s_imp_drh);
   TypedData_Get_Struct(ads_conn, a_ads_connection, &ads_connection_type, s_ads_conn);

   s_str = StringValueCStr(str);

   result = s_imp_drh->api.ads_connect(s_ads_conn, (UNSIGNED8 *)s_str);

   return (INT2FIX(result));
}

#ads_describe_bind_param(VALUEimp_drh, VALUEads_stmt, VALUEindex) ⇒ Array

Describes the bind parameters of a prepared statement.

This function allows the caller to determine information about parameters
to a prepared statement. Depending on the type of the prepared statement
( call to stored procedure or a DML ), only some information will be
provided. The information that will always be provided is the direction
of the parameters ( input, output, or input-output ).

<b>Parameters</b>:
- <tt>VALUE imp_drh</tt> -- An initialized API structure to finalize.
- <tt>VALUE ads_stmt</tt> -- A statement object that was returned from ads_prepare(  ).
- <tt>VALUE index</tt> -- The index of the parameter. This should be a number between 0 and ads_num_params(  )-  1.

<b>Returns</b>:
- <tt>VALUE result</tt>: <tt>1</tt> on success or <tt>0</tt> on failure.
- <tt>VALUE bind_param</tt>: The described param object.

Returns:

  • (Array)


1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
# File 'ext/advantage/advantage.c', line 1165

static VALUE
static_AdvantageInterface_ads_describe_bind_param(VALUE imp_drh, VALUE ads_stmt, VALUE index)
{
   imp_drh_st *s_imp_drh;
   ADSHANDLE s_stmt;
   a_ads_bind_param *s_ads_bind_param;
   UNSIGNED32 result;
   UNSIGNED32 s_index;
   VALUE tdata;
   VALUE multi_result;

   s_ads_bind_param = malloc(sizeof(a_ads_bind_param));
   memset(s_ads_bind_param, 0, sizeof(a_ads_bind_param));

   Data_Get_Struct(imp_drh, imp_drh_st, s_imp_drh);
   s_stmt = (ADSHANDLE)NUM2ULL(ads_stmt);
   s_index = NUM2INT(index);

   result = s_imp_drh->api.ads_describe_bind_param(s_stmt, s_index, s_ads_bind_param);

   //FIXME handle failed result

   multi_result = rb_ary_new();

   rb_ary_push(multi_result, INT2FIX(result));

   tdata = Data_Wrap_Struct(cA_ads_bind_param, 0, 0, s_ads_bind_param);
   rb_ary_push(multi_result, tdata);

   return (multi_result);
}

#ads_disconnect(VALUEimp_drh, VALUEads_conn) ⇒ nil

Disconnect an already established connection.

This function disconnects the connection. Any
uncommitted transactions will be rolled back.

<b>Parameters</b>:
- <tt>VALUE imp_drh</tt> -- An initialized API structure to finalize.
- <tt>VALUE ads_conn</tt> -- A connection object that was connected by ads_connect(  ).

<b>Returns</b>:
- <tt>nil</tt>.

Returns:

  • (nil)


431
432
433
434
435
436
437
438
439
440
441
442
443
# File 'ext/advantage/advantage.c', line 431

static VALUE
static_AdvantageInterface_ads_disconnect(VALUE imp_drh, VALUE ads_conn)
{
   imp_drh_st *s_imp_drh;
   a_ads_connection *s_ads_conn;

   Data_Get_Struct(imp_drh, imp_drh_st, s_imp_drh);
   TypedData_Get_Struct(ads_conn, a_ads_connection, &ads_connection_type, s_ads_conn);

   s_imp_drh->api.ads_disconnect(s_ads_conn);

   return (Qnil);
}

#ads_error(VALUEimp_drh, VALUEads_conn) ⇒ Array

Retrieves the last error code and message.

This function can be used to retrieve the last error code and message
stored in the connection object.

<b>Parameters</b>:
- <tt>VALUE imp_drh</tt> -- An initialized API structure to finalize.
- <tt>VALUE ads_conn</tt> -- A connection object that was connected by ads_connect(  ).

<b>Returns</b>:
- <tt>VALUE result</tt>: The last error code. Positive values are warnings, negative values are errors, and <tt>0</tt> is success.
- <tt>VALUE errstr</tt>: The error message corresponding to the error code.

Returns:

  • (Array)


519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
# File 'ext/advantage/advantage.c', line 519

static VALUE
static_AdvantageInterface_ads_error(VALUE imp_drh, VALUE ads_conn)
{
   imp_drh_st *s_imp_drh;
   a_ads_connection *s_ads_conn;
   char s_buffer[255];
   UNSIGNED32 result;
   VALUE multi_result;

   Data_Get_Struct(imp_drh, imp_drh_st, s_imp_drh);
   TypedData_Get_Struct(ads_conn, a_ads_connection, &ads_connection_type, s_ads_conn);

   result = s_imp_drh->api.ads_error(s_ads_conn, (UNSIGNED8 *)s_buffer, 255);

   multi_result = rb_ary_new();

   rb_ary_push(multi_result, INT2FIX(result));
   rb_ary_push(multi_result, rb_str_new2(s_buffer));

   return (multi_result);
}

#ads_execute(VALUEimp_drh, VALUEads_stmt) ⇒ Object

Executes a prepared statement.

<b>Parameters</b>:
- <tt>VALUE imp_drh</tt> -- An initialized API structure to finalize.
- <tt>VALUE ads_stmt</tt> -- A statement object that was created by ads_prepare(  ) or ads_execute_direct(  ).

<b>Returns</b>:
- <tt>VALUE result</tt>: <tt>1</tt> on successful execution, <tt>0</tt> otherwise.


1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
# File 'ext/advantage/advantage.c', line 1092

static VALUE
static_AdvantageInterface_ads_execute(VALUE imp_drh, VALUE ads_stmt)
{
   imp_drh_st *s_imp_drh;
   ADSHANDLE s_stmt;
   UNSIGNED32 result;

   Data_Get_Struct(imp_drh, imp_drh_st, s_imp_drh);
   //Data_Get_Struct( ads_stmt, ADSHANDLE, s_ads_stmt );
   s_stmt = (ADSHANDLE)NUM2ULL(ads_stmt);

   //printf(  "CEXT s_ads_stmt: %d \n", s_stmt );
   result = s_imp_drh->api.ads_execute(s_stmt);
   /*if (  result != AE_SUCCESS  )
      return ( 0 );
   else
      return ( 1 );*/
   return (INT2FIX(result));
}

#ads_execute_direct(VALUEimp_drh, VALUEads_conn, VALUEsql) ⇒ Object

Executes a SQL statement and possibly returns a result set.

This function executes the SQL statement specified by the string argument.
This function is suitable if you want to prepare and then execute a
statement, and can be used instead of calling ads_prepare(  ) followed
by ads_execute(  ).

This function cannot be used for executing a SQL statement with
parameters.

<b>Parameters</b>:
- <tt>VALUE imp_drh</tt> -- An initialized API structure to finalize.
- <tt>VALUE ads_conn</tt> -- A connection object that was connected by ads_connect(  ).
- <tt>VALUE sql</tt> -- A SQL query string.

<b>Returns</b>:
- <tt>VALUE result</tt>: A query result set if successful, nil if failed.


601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
# File 'ext/advantage/advantage.c', line 601

static VALUE
static_AdvantageInterface_ads_execute_direct(VALUE imp_drh, VALUE ads_conn, VALUE sql)
{
   imp_drh_st *s_imp_drh;
   a_ads_connection *s_ads_conn;
   ADSHANDLE resultset = 0;
   char *s_sql;
   VALUE tdata;

   s_sql = StringValueCStr(sql);

   Data_Get_Struct(imp_drh, imp_drh_st, s_imp_drh);
   TypedData_Get_Struct(ads_conn, a_ads_connection, &ads_connection_type, s_ads_conn);

   resultset = s_imp_drh->api.ads_execute_direct(s_ads_conn, (UNSIGNED8 *)s_sql);

   if (resultset)
   {
      tdata = ULL2NUM((unsigned long long)resultset);
   }
   else
   {
      tdata = Qnil;
   }

   return (tdata);
}

#ads_execute_immediate(VALUEimp_drh, VALUEads_conn, VALUEsql) ⇒ Object

Executes a SQL statement immediately without returning a result set.

This function executes the specified SQL statement immediately. It is
useful for SQL statements that do not return a result set.

<b>Parameters</b>:
- <tt>VALUE imp_drh</tt> -- An initialized API structure to finalize.
- <tt>VALUE ads_conn</tt> -- A connection object that was connected by ads_connect(  ).
- <tt>VALUE sql</tt> -- A SQL query string.

<b>Returns</b>:
- <tt>VALUE result</tt>: <tt>1</tt> on success, <tt>0</tt> on failure.


560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
# File 'ext/advantage/advantage.c', line 560

static VALUE
static_AdvantageInterface_ads_execute_immediate(VALUE imp_drh, VALUE ads_conn, VALUE sql)
{
   imp_drh_st *s_imp_drh;
   a_ads_connection *s_ads_conn;
   char *s_sql;
   UNSIGNED32 result;

   s_sql = StringValueCStr(sql);

   Data_Get_Struct(imp_drh, imp_drh_st, s_imp_drh);
   TypedData_Get_Struct(ads_conn, a_ads_connection, &ads_connection_type, s_ads_conn);

   result = s_imp_drh->api.ads_execute_immediate(s_ads_conn, (UNSIGNED8 *)s_sql);

   return (INT2FIX(result));
}

#ads_fetch_absolute(VALUEimp_drh, VALUEads_stmt, VALUEoffset) ⇒ Object

Fetches data at a specific row number in the result set.

This function moves the current row in the result set to the row number
specified and fetches the data at that row.

<b>Parameters</b>:
- <tt>VALUE imp_drh</tt> -- An initialized API structure to finalize.
- <tt>VALUE ads_stmt</tt> -- A statement object that was executed by ads_execute(  ) or ads_execute_direct(  ).
- <tt>VALUE offset</tt> -- The row number to be fetched. The first row is <tt>1</tt>, the last row is <tt>-1</tt>.

<b>Returns</b>:
- <tt>VALUE result</tt>: <tt>1</tt> if the fetch was successfully, <tt>0</tt> otherwise.


1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
# File 'ext/advantage/advantage.c', line 1367

static VALUE
static_AdvantageInterface_ads_fetch_absolute(VALUE imp_drh, VALUE ads_stmt, VALUE offset)
{
   imp_drh_st *s_imp_drh;
   ADSHANDLE s_stmt;
   UNSIGNED32 s_offset;
   UNSIGNED32 result;

   Data_Get_Struct(imp_drh, imp_drh_st, s_imp_drh);
   //Data_Get_Struct( ads_stmt, ADSHANDLE, s_ads_stmt );
   s_stmt = (ADSHANDLE)NUM2ULL(ads_stmt);
   s_offset = NUM2INT(offset);
   result = s_imp_drh->api.ads_fetch_absolute(s_stmt, s_offset);

   return (INT2FIX(result));
}

#ads_fetch_next(VALUEimp_drh, VALUEads_stmt) ⇒ Object

Fetches the next row from the result set.

This function fetches the next row from the result set. When the result
object is first created, the current row pointer is set to point before
the first row ( that is, row 0 ).
This function advances the row pointer first and then fetches the data
at the new row.

<b>Parameters</b>:
- <tt>VALUE imp_drh</tt> -- An initialized API structure to finalize.
- <tt>VALUE ads_stmt</tt> -- A statement object that was created by ads_prepare(  ) or ads_execute_direct(  ).

<b>Returns</b>:
- <tt>VALUE result</tt>: <tt>1</tt> on successful fetch, <tt>0</tt> otherwise.


763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
# File 'ext/advantage/advantage.c', line 763

static VALUE
static_AdvantageInterface_ads_fetch_next(VALUE imp_drh, VALUE ads_stmt)
{
   imp_drh_st *s_imp_drh;
   ADSHANDLE s_stmt;
   UNSIGNED32 result;

   Data_Get_Struct(imp_drh, imp_drh_st, s_imp_drh);
   //Data_Get_Struct( ads_stmt, ADSHANDLE, s_stmt );
   s_stmt = (ADSHANDLE)NUM2ULL(ads_stmt);

   result = s_imp_drh->api.ads_fetch_next(s_stmt);

   return (INT2FIX(result));
}

#ads_fini(VALUEimp_drh) ⇒ nil

Finalizes the interface.

Thus function frees any resources allocated by the API.

<b>Parameters</b>:
- <tt>VALUE imp_drh</tt> -- An initialized API structure to finalize.

<b>Returns</b>:
- <tt>nil</tt>.

Returns:

  • (nil)


488
489
490
491
492
493
494
495
496
497
498
# File 'ext/advantage/advantage.c', line 488

static VALUE
static_AdvantageInterface_ads_fini(VALUE imp_drh)
{
   imp_drh_st *s_imp_drh;

   Data_Get_Struct(imp_drh, imp_drh_st, s_imp_drh);

   s_imp_drh->api.ads_fini();

   return (Qnil);
}

#ads_free_connection(VALUEimp_drh, VALUEads_conn) ⇒ nil

Frees the resources associated with a connection object.

<b>Parameters</b>:
- <tt>VALUE imp_drh</tt> -- An initialized API structure to finalize.
- <tt>VALUE ads_conn</tt> -- A connection object that was disconnected by ads_disconnect(  ).

<b>Returns</b>:
- <tt>nil</tt>.

Returns:

  • (nil)


459
460
461
462
463
464
465
466
467
468
469
470
471
# File 'ext/advantage/advantage.c', line 459

static VALUE
static_AdvantageInterface_ads_free_connection(VALUE imp_drh, VALUE ads_conn)
{
   imp_drh_st *s_imp_drh;
   a_ads_connection *s_ads_conn;

   Data_Get_Struct(imp_drh, imp_drh_st, s_imp_drh);
   TypedData_Get_Struct(ads_conn, a_ads_connection, &ads_connection_type, s_ads_conn);

   s_imp_drh->api.ads_free_connection(s_ads_conn);

   return (Qnil);
}

#ads_free_stmt(VALUEimp_drh, VALUEads_stmt) ⇒ nil

Frees resources associated with a prepared statement object.

This function frees the resources associated with a prepared statement
object.

<b>Parameters</b>:
- <tt>VALUE imp_drh</tt> -- An initialized API structure to finalize.
- <tt>VALUE ads_stmt</tt> -- A statement object that was created by ads_prepare(  ) or ads_execute_direct(  ).

<b>Returns</b>:
- <tt>nil</tt>.

Returns:

  • (nil)


994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
# File 'ext/advantage/advantage.c', line 994

static VALUE
static_AdvantageInterface_ads_free_stmt(VALUE imp_drh, VALUE ads_stmt)
{
   imp_drh_st *s_imp_drh;
   ADSHANDLE s_stmt;
   int i;
   int number_of_params = 0;
   a_ads_bind_param_info bind_info;

   Data_Get_Struct(imp_drh, imp_drh_st, s_imp_drh);
   //Data_Get_Struct( ads_stmt, ADSHANDLE, s_ads_stmt );
   s_stmt = (ADSHANDLE)NUM2ULL(ads_stmt);

   number_of_params = s_imp_drh->api.ads_num_params(s_stmt);

   for (i = 0; i < number_of_params; i++)
   {
      if (s_imp_drh->api.ads_get_bind_param_info(s_stmt, i, &bind_info))
      {
         // We don't free bind_info.name as it's not allocated
         // if ( bind_info.name ) {free ( bind_info.name );}

         if (bind_info.input_value.is_null)
         {
            free(bind_info.input_value.is_null);
         }
         if (bind_info.input_value.length)
         {
            free(bind_info.input_value.length);
         }
         if (bind_info.input_value.buffer)
         {
            free(bind_info.input_value.buffer);
         }

         if (bind_info.output_value.is_null)
         {
            free(bind_info.output_value.is_null);
         }
         if (bind_info.output_value.length)
         {
            free(bind_info.output_value.length);
         }
         if (bind_info.output_value.buffer)
         {
            free(bind_info.output_value.buffer);
         }
      }
   }

   s_imp_drh->api.ads_free_stmt(s_stmt);

   return (Qnil);
}

#ads_get_bind_param_info(VALUEimp_drh, VALUEads_stmt, VALUEindex) ⇒ Array

Gets bound parameter info.

This function retrieves information about the parameters that were
bound using ads_bind_param(  ).

<b>Parameters</b>:
- <tt>VALUE imp_drh</tt> -- An initialized API structure to finalize.
- <tt>VALUE ads_stmt</tt> -- A statement object that was returned from ads_prepare(  ).
- <tt>VALUE index</tt> -- The index of the parameter. This should be a number between 0 and ads_num_params(  ) - 1.

<b>Returns</b>:
- <tt>VALUE result</tt>: <tt>1</tt> on success or <tt>0</tt> on failure.
- <tt>VALUE bind_param</tt>: The described param object.

Returns:

  • (Array)


1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
# File 'ext/advantage/advantage.c', line 1252

static VALUE
static_AdvantageInterface_ads_get_bind_param_info(VALUE imp_drh, VALUE ads_stmt, VALUE index)
{
   imp_drh_st *s_imp_drh;
   ADSHANDLE s_stmt;
   a_ads_bind_param_info s_ads_bind_param_info;
   UNSIGNED32 result;
   UNSIGNED32 s_index;
   VALUE tdata;
   VALUE multi_result;

   Data_Get_Struct(imp_drh, imp_drh_st, s_imp_drh);
   s_stmt = (ADSHANDLE)NUM2ULL(ads_stmt);
   s_index = NUM2INT(index);

   result = s_imp_drh->api.ads_get_bind_param_info(s_stmt, s_index, &s_ads_bind_param_info);

   //FIXME handle failed result
   multi_result = rb_ary_new();

   rb_ary_push(multi_result, INT2FIX(result));

   // FIXME: Is this safe to be on the stack?
   tdata = Data_Wrap_Struct(cA_ads_bind_param_info, 0, 0, &s_ads_bind_param_info);
   rb_ary_push(multi_result, tdata);

   return (multi_result);
}

#ads_get_column(VALUEimp_drh, VALUEads_stmt, VALUEcol_num) ⇒ Array

Retrieves the data fetched for the specified column.

<b>Parameters</b>:
- <tt>VALUE imp_drh</tt> -- An initialized API structure to finalize.
- <tt>VALUE ads_stmt</tt> -- A statement object that was created by ads_prepare(  ) or ads_execute_direct(  ).
- <tt>VALUE col_num</tt> -- The number of the column to be retrieved. A column number is between 0 and ads_num_cols(  ) - 1.

<b>Returns</b>:
- <tt>VALUE column_value</tt>: The value of the column. nil is returned if the value was NULL.

Returns:

  • (Array)


704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
# File 'ext/advantage/advantage.c', line 704

static VALUE
static_AdvantageInterface_ads_get_column(VALUE imp_drh, VALUE ads_stmt, VALUE col_num)
{
   imp_drh_st *s_imp_drh;
   ADSHANDLE s_stmt;
   UNSIGNED32 s_col_num;
   a_ads_data_value value;
   UNSIGNED32 result;
   VALUE multi_result;

   Data_Get_Struct(imp_drh, imp_drh_st, s_imp_drh);
   //Data_Get_Struct( ads_stmt, ADSHANDLE, s_stmt );
   s_stmt = (ADSHANDLE)NUM2ULL(ads_stmt);
   s_col_num = NUM2INT(col_num);

   result = s_imp_drh->api.ads_get_column(s_stmt, s_col_num, &value);

   multi_result = rb_ary_new();
   rb_ary_push(multi_result, INT2FIX(result));

   if (!result)
   {
      rb_ary_push(multi_result, Qnil);
   }
   else
   {
      if (*value.is_null)
      {
         rb_ary_push(multi_result, Qnil);
      }
      else
      {
         rb_ary_push(multi_result, C2RB(&value));
      }
   }

   return (multi_result);
}

#ads_get_column_info(VALUEimp_drh, VALUEads_stmt, VALUEcol_num) ⇒ Array

Fetches the next row from the result set.

This function fetches the next row from the result set. When the result
object is first created, the current row pointer is set to point before
the first row ( that is, row 0 ).
This function advances the row pointer first and then fetches the data
at the new row.

<b>Parameters</b>:
- <tt>VALUE imp_drh</tt> -- An initialized API structure to finalize.
- <tt>VALUE ads_stmt</tt> -- A statement object that was created by ads_prepare(  ) or ads_execute_direct(  ).
- <tt>VALUE col_num</tt> -- The number of the column to be retrieved. A column number is between 0 and ads_num_cols(  ) - 1.

<b>Returns</b>:
- <tt>VALUE result</tt>: <tt>1</tt> on success. Returns <tt>0</tt> if the column index is out of range, or if the statement does not return a result set.
- <tt>VALUE col_num</tt>: The number of the column retrieved.
- <tt>VALUE name</tt>: The name of the column.
- <tt>VALUE type</tt>: The type of the column data.
- <tt>VALUE native_type</tt>: The Advantage native type of the column data.
- <tt>VALUE precision</tt>: The precision of the column.
- <tt>VALUE scale</tt>: The scale of the column.
- <tt>VALUE max_size</tt>: The maximum size a data value in this column can take.
- <tt>VALUE nullable</tt>: The nullability of the column.

Returns:

  • (Array)


808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
# File 'ext/advantage/advantage.c', line 808

static VALUE
static_AdvantageInterface_ads_get_column_info(VALUE imp_drh, VALUE ads_stmt, VALUE col_num)
{
   imp_drh_st *s_imp_drh;
   ADSHANDLE s_stmt;
   UNSIGNED32 s_col_num;
   a_ads_column_info info;
   UNSIGNED32 result;
   VALUE multi_result;

   Data_Get_Struct(imp_drh, imp_drh_st, s_imp_drh);
   //Data_Get_Struct( ads_stmt, ADSHANDLE, s_stmt );
   s_stmt = (ADSHANDLE)NUM2ULL(ads_stmt);
   s_col_num = NUM2INT(col_num);

   result = s_imp_drh->api.ads_get_column_info(s_stmt, s_col_num, &info);

   multi_result = rb_ary_new();
   rb_ary_push(multi_result, INT2FIX(result));
   rb_ary_push(multi_result, col_num);
   rb_ary_push(multi_result, rb_str_new2((char *)info.name));
   rb_ary_push(multi_result, INT2FIX(info.type));
   rb_ary_push(multi_result, INT2FIX(info.native_type));
   rb_ary_push(multi_result, INT2FIX(info.precision));
   rb_ary_push(multi_result, INT2FIX(info.scale));
   rb_ary_push(multi_result, INT2FIX(info.max_size));
   rb_ary_push(multi_result, INT2FIX(info.nullable));

   return (multi_result);
}

#ads_get_next_result(VALUEimp_drh, VALUEads_stmt) ⇒ Object

Advances to the next result set in a multiple result set query.

If a query ( such as a call to a stored procedure ) returns multiple result
sets, then this function advances from the current result set to the next.

<b>Parameters</b>:
- <tt>VALUE imp_drh</tt> -- An initialized API structure to finalize.
- <tt>VALUE ads_stmt</tt> -- A statement object that was executed by ads_execute(  ) or ads_execute_direct(  ).

<b>Returns</b>:
- <tt>VALUE result</tt>: <tt>1</tt> if was successfully able to advance to the next result set, <tt>0</tt> otherwise.


1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
# File 'ext/advantage/advantage.c', line 1333

static VALUE
static_AdvantageInterface_ads_get_next_result(VALUE imp_drh, VALUE ads_stmt)
{
   imp_drh_st *s_imp_drh;
   ADSHANDLE s_stmt;
   UNSIGNED32 result;

   Data_Get_Struct(imp_drh, imp_drh_st, s_imp_drh);
   //Data_Get_Struct( ads_stmt, ADSHANDLE, s_ads_stmt );
   s_stmt = (ADSHANDLE)NUM2ULL(ads_stmt);

   result = s_imp_drh->api.ads_get_next_result(s_stmt);

   return (INT2FIX(result));
}

#ads_init(VALUEimp_drh) ⇒ Array

Initializes the interface.

<b>Parameters</b>:
- <tt>VALUE imp_drh</tt> -- An initialized API structure to finalize.

<b>Returns</b>:
- <tt>VALUE result</tt>: <tt>1</tt> on success, <tt>0</tt> on failure.
- <tt>VALUE version</tt>: The maximum API version that is supported.

Returns:

  • (Array)


289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
# File 'ext/advantage/advantage.c', line 289

static VALUE
static_AdvantageInterface_ads_init(VALUE imp_drh)
{
   imp_drh_st *s_imp_drh;
   UNSIGNED32 result;
   UNSIGNED32 s_version_available;
   VALUE multi_result;

   Data_Get_Struct(imp_drh, imp_drh_st, s_imp_drh);

   multi_result = rb_ary_new();

   if (&(s_imp_drh->api) == NULL)
   {
      rb_ary_push(multi_result, INT2FIX(0));
      rb_ary_push(multi_result, Qnil);
   }
   else
   {
      result = s_imp_drh->api.ads_init((UNSIGNED8 *)"RUBY", 1, &s_version_available);
      rb_ary_push(multi_result, INT2FIX(result));
      rb_ary_push(multi_result, INT2FIX(s_version_available));
   }

   return (multi_result);
}

#ads_new_connection(VALUEimp_drh) ⇒ Object

Creates a connection object.

An API connection object needs to be created before a database connection
is established. Errors can be retrieved from the connection object. Only
one request can be processed on a connection at a time.

<b>Parameters</b>:
- <tt>VALUE imp_drh</tt> -- An initialized API structure to finalize.

<b>Returns</b>:
- <tt>VALUE connection</tt>: A connection object.


333
334
335
336
337
338
339
340
341
342
343
344
345
346
# File 'ext/advantage/advantage.c', line 333

static VALUE
static_AdvantageInterface_ads_new_connection(VALUE imp_drh)
{
   imp_drh_st *s_imp_drh;
   a_ads_connection *ptr;
   VALUE tdata;

   Data_Get_Struct(imp_drh, imp_drh_st, s_imp_drh);
   ptr = s_imp_drh->api.ads_new_connection();

   tdata = TypedData_Wrap_Struct(cA_ads_connection, &ads_connection_type, ptr);

   return (tdata);
}

#ads_num_cols(VALUEimp_drh, VALUEads_stmt) ⇒ Object

Returns number of columns in the result set.

<b>Parameters</b>:
- <tt>VALUE imp_drh</tt> -- An initialized API structure to finalize.
- <tt>VALUE ads_stmt</tt> -- A statement object that was created by ads_prepare(  ) or ads_execute_direct(  ).

<b>Returns</b>:
- <tt>VALUE num_cols</tt>: The number of columns in the result set or <tt>-1</tt> on a failure.


643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
# File 'ext/advantage/advantage.c', line 643

static VALUE
static_AdvantageInterface_ads_num_cols(VALUE imp_drh, VALUE ads_stmt)
{
   imp_drh_st *s_imp_drh;
   ADSHANDLE s_stmt;
   UNSIGNED32 result;

   Data_Get_Struct(imp_drh, imp_drh_st, s_imp_drh);
   //Data_Get_Struct( ads_stmt, ADSHANDLE, s_stmt );
   s_stmt = (ADSHANDLE)NUM2ULL(ads_stmt);

   result = s_imp_drh->api.ads_num_cols(s_stmt);

   return (INT2NUM(result));
}

#ads_num_params(VALUEimp_drh, VALUEads_stmt) ⇒ Object

Returns the number of parameters that are expected for a prepared

statement.

This function retrieves information about the parameters that were bound
using ads_bind_param(  ).

<b>Parameters</b>:
- <tt>VALUE imp_drh</tt> -- An initialized API structure to finalize.
- <tt>VALUE ads_stmt</tt> -- A statement object that was returned from ads_prepare(  ).

<b>Returns</b>:
- <tt>VALUE result</tt>: The number of parameters that are expected. <tt>-1</tt> if the ads_stmt object is not valid.


1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
# File 'ext/advantage/advantage.c', line 1299

static VALUE
static_AdvantageInterface_ads_num_params(VALUE imp_drh, VALUE ads_stmt)
{
   imp_drh_st *s_imp_drh;
   ADSHANDLE s_stmt;
   UNSIGNED32 result;

   Data_Get_Struct(imp_drh, imp_drh_st, s_imp_drh);
   //Data_Get_Struct( ads_stmt, ADSHANDLE, s_ads_stmt );
   s_stmt = (ADSHANDLE)NUM2ULL(ads_stmt);

   result = s_imp_drh->api.ads_num_params(s_stmt);

   return (INT2FIX(result));
}

#ads_num_rows(VALUEimp_drh, VALUEads_stmt) ⇒ Object

Returns number of rows in the result set.

<b>Parameters</b>:
- <tt>VALUE imp_drh</tt> --  An initialized API structure to finalize.
- <tt>VALUE ads_stmt</tt> -- A statement object that was created by ads_prepare(  ) or ads_execute_direct(  ).

<b>Returns</b>:
- <tt>VALUE num_rows</tt>: The number of rows in the result set or <tt>-1</tt> on a failure.


673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
# File 'ext/advantage/advantage.c', line 673

static VALUE
static_AdvantageInterface_ads_num_rows(VALUE imp_drh, VALUE ads_stmt)
{
   imp_drh_st *s_imp_drh;
   ADSHANDLE s_stmt;
   UNSIGNED32 result;

   Data_Get_Struct(imp_drh, imp_drh_st, s_imp_drh);
   //Data_Get_Struct( ads_stmt, ADSHANDLE, s_stmt );
   s_stmt = (ADSHANDLE)NUM2ULL(ads_stmt);

   result = s_imp_drh->api.ads_num_rows(s_stmt);

   return (INT2FIX(result));
}

#ads_prepare(VALUEimp_drh, VALUEads_conn, VALUEsql) ⇒ Object

Prepares a SQL statement.

This function prepares the supplied SQL string. Execution does not
happen until ads_execute(  ) is called. The returned statement object
should be freed using ads_free_stmt(  ).

<b>Parameters</b>:
- <tt>VALUE imp_drh</tt> -- An initialized API structure to finalize.
- <tt>VALUE ads_conn</tt> -- A connection object that was connected by ads_connect(  ).
- <tt>VALUE sql</tt> -- SQL query to prepare.

<b>Returns</b>:
- <tt>VALUE stmt</tt>: A statement object, or nil on failure. The statement object can be used by ads_execute(  ) to execute the statement.


948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
# File 'ext/advantage/advantage.c', line 948

static VALUE
static_AdvantageInterface_ads_prepare(VALUE imp_drh, VALUE ads_conn, VALUE sql)
{
   imp_drh_st *s_imp_drh;
   a_ads_connection *s_ads_conn;
   ADSHANDLE s_stmt = 0;
   char *s_sql;
   VALUE tdata;

   s_sql = StringValueCStr(sql);

   Data_Get_Struct(imp_drh, imp_drh_st, s_imp_drh);
   TypedData_Get_Struct(ads_conn, a_ads_connection, &ads_connection_type, s_ads_conn);

   //EJS Passing FALSE for isUnicode
   s_stmt = s_imp_drh->api.ads_prepare(s_ads_conn, (UNSIGNED8 *)s_sql, '\0');

   if (s_stmt)
   {
      tdata = ULL2NUM((unsigned long long)s_stmt);
   }
   else
   {
      tdata = Qnil;
   }

   return (tdata);
}

#ads_reset(VALUEimp_drh, VALUEads_stmt) ⇒ Object

Parameters:

- <tt>VALUE imp_drh</tt> -- An initialized API structure to finalize.
- <tt>VALUE ads_stmt</tt> -- A statement object that was created by ads_prepare(  ) or ads_execute_direct(  ).

<b>Returns</b>:
- <tt>VALUE result</tt>: <tt>1</tt> on successful execution, <tt>0</tt> otherwise.


1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
# File 'ext/advantage/advantage.c', line 1062

static VALUE
static_AdvantageInterface_ads_reset(VALUE imp_drh, VALUE ads_stmt)
{
   imp_drh_st *s_imp_drh;
   ADSHANDLE s_stmt;
   UNSIGNED32 result;

   Data_Get_Struct(imp_drh, imp_drh_st, s_imp_drh);
   //Data_Get_Struct( ads_stmt, ADSHANDLE, s_ads_stmt );
   s_stmt = (ADSHANDLE)NUM2ULL(ads_stmt);

   result = s_imp_drh->api.ads_reset(s_stmt);

   return (INT2FIX(result));
}

#ads_rollback(VALUEimp_drh, VALUEads_conn) ⇒ Object

Rolls back the current transaction.

<b>Parameters</b>:
- <tt>VALUE imp_drh</tt> -- An initialized API structure to finalize.
- <tt>VALUE ads_conn</tt> -- A connection object that was connected by ads_connect(  ).

<b>Returns</b>:
- <tt>VALUE result</tt>: <tt>1</tt> on successful rollback, <tt>0</tt> otherwise.


913
914
915
916
917
918
919
920
921
922
923
924
925
926
# File 'ext/advantage/advantage.c', line 913

static VALUE
static_AdvantageInterface_ads_rollback(VALUE imp_drh, VALUE ads_conn)
{
   imp_drh_st *s_imp_drh;
   a_ads_connection *s_ads_conn;
   UNSIGNED32 result;

   Data_Get_Struct(imp_drh, imp_drh_st, s_imp_drh);
   TypedData_Get_Struct(ads_conn, a_ads_connection, &ads_connection_type, s_ads_conn);

   result = s_imp_drh->api.ads_rollback(s_ads_conn);

   return (INT2FIX(result));
}

#ads_sqlstate(VALUEimp_drh, VALUEads_conn) ⇒ Object

Retrieves the current SQL state.

<b>Parameters</b>:
- <tt>VALUE imp_drh</tt> -- An initialized API structure to finalize.
- <tt>VALUE ads_conn</tt> -- A connection object that was connected by ads_connect(  ).

<b>Returns</b>:
- <tt>VALUE sqlstate_str</tt>: The SQL State.


1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
# File 'ext/advantage/advantage.c', line 1398

static VALUE
static_AdvantageInterface_ads_sqlstate(VALUE imp_drh, VALUE ads_conn)
{
   imp_drh_st *s_imp_drh;
   a_ads_connection *s_ads_conn;
   UNSIGNED32 result;
   char s_buffer[255];

   Data_Get_Struct(imp_drh, imp_drh_st, s_imp_drh);
   TypedData_Get_Struct(ads_conn, a_ads_connection, &ads_connection_type, s_ads_conn);

   result = s_imp_drh->api.ads_sqlstate(s_ads_conn, (UNSIGNED8 *)s_buffer, sizeof(s_buffer));

   if (result)
      return (rb_str_new(s_buffer, strlen(s_buffer)));
   else
      return Qnil;
}

#AdsBeginTransaction(VALUEimp_drh, VALUEads_conn) ⇒ Object

Starts a transaction on the current connection.

<b>Parameters</b>:
- <tt>VALUE imp_drh</tt> -- An initialized API structure to finalize.
- <tt>VALUE ads_conn</tt> -- A connection object that was connected by ads_connect(  ).

<b>Returns</b>:
- <tt>VALUE result</tt>: <tt>1</tt> on successful begining a transaction, <tt>0</tt> otherwise.


853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
# File 'ext/advantage/advantage.c', line 853

static VALUE
static_AdvantageInterface_AdsBeginTransaction(VALUE imp_drh, VALUE ads_conn)
{
   imp_drh_st *s_imp_drh;
   a_ads_connection *s_ads_conn;
   UNSIGNED32 result;

   Data_Get_Struct(imp_drh, imp_drh_st, s_imp_drh);
   TypedData_Get_Struct(ads_conn, a_ads_connection, &ads_connection_type, s_ads_conn);

   result = s_imp_drh->api.AdsBeginTransaction(s_ads_conn->hConnect);
   if (result == 0)
      return (INT2FIX(1));
   else
      return (INT2FIX(0));
}