602SQL Documentation Index  

Format of client variable descriptions in functions for XML import and export

This describes the hostvars parameter of the wb_export_to_XML, wb_export_to_XML_buffer, wb_import_from_XML and wb_import_from_XML_buffer functions.

This parameter can have a NULL value if you do not wish to pass any client variable descriptions (in this case you do not need to specify the hostvars parameter when calling the function), or it must be an array with the following structure:

Parameter value conversion

The PHP parameter values are converted into database type values specified in the parameter description before data transfer. After the transfer is complete, the output parameter values are converted back.

Input parameter conversion

PHP NULL value conversion

If the PHP NULL value is passed (for any parameter type), the SQL Server will receive the SQL NULL value of the corresponding database type.

Converting other PHP values

input parameter typeallowed PHP values
ATT_BOOLEAN boolean type values, or values that can be converted to this PHP type
ATT_INT8, ATT_INT16, ATT_INT32, ATT_INT64 int type values, or values that can be converted to this PHP type; if the value exceeds the database type range, an error will occur
ATT_INT8, ATT_INT16, ATT_INT32, ATT_INT64"scale">0 int or float type values, or values that can be converted to this PHP types; if the value exceeds the database type range, an error will occur
ATT_MONEY, ATT_FLOAT float type values, or values that can be converted to this PHP type; if the value exceeds the database type range, an error will occur
ATT_STRING, ATT_TEXT string type values, or values that can be converted to this PHP type
ATT_STRING, ATT_TEXT with  "wide_char"=TRUE

string, type values, or values that can be converted to this PHP type; moreover:

  • If the client encoding is WB_ENC_ASCII, then the value must be an ASCII string
  • If the client encoding is WB_ENC_WIN1250, then the value must be a string in the Windows CP 1250 coding
  • If the client encoding is WB_ENC_WIN1252, then the value must be a string in the Windows CP 1252 coding
  • If the client encoding is WB_ENC_ISO_8859_2, then the value must be a string in the ISO-8859-2 coding
  • If the client encoding is WB_ENC_UTF8, then the value must be an UTF-8 string

The passed value will be sent to the SQL Server after it is converted to UCS-2 coding, however the original PHP value is unaffected.

ATT_DATE
  • Values of the int type, the number is taken as Unix time (the time instant that is a certain number of seconds from the Unix Epoch, 1.1.1970, 00:00 UTC) and the day (date) this instant belongs to is converted to the SQL DATE type
  • Values of the string type, the string must be a valid notation of the DATE type constant according to the 602SQL API Str2date function.
  • Other PHP type values will result in an error
ATT_TIME

Value of the string type, or value that can be converted to this type, the string must be a valid notation of a TIME type constant according to the 602SQL API Str2time function.

ATT_TIMESTAMP
  • Values of the int type, the number is taken as Unix time and the TIMESTAMP type value that belongs to the same time instant, is passed to the SQL Server
  • Values of the string type, the string must be a valid notation of the TIMESTAMP according to the 602SQL API Str2timestamp function.
  • Other PHP type values will result in an error

Output parameter conversion

NULL value

The NULL value is always returned as the PHP NULL value.

Other values

output parameter typePHP value
ATT_BOOLEAN PHP type boolean
Integer types up to 32-bit (e.g. ATT_INT8, ATT_INT16 and ATT_INT32 PHP type int
ATT_INT64 If this value can be converted to a 32-bit int type, then it will be returned as a value of this type, otherwise it will be a float (however, in this case, number accuracy will be affected).
integer types ATT_INT8, ATT_INT16, ATT_INT32 and ATT_INT64, that have "scale">0 PHP type float
ATT_MONEY, ATT_FLOAT PHP type float
ATT_STRING, ATT_TEXT PHP type string
ATT_STRING, ATT_TEXT"wide_char"=TRUE PHP type string; the return string will be in UTF-8
ATT_DATE PHP type int; the return number is the time of the first second (e.g. 00:00) of that day, that is represented by the DATE type value
ATT_TIME PHP type string; the return string will contain the given time notation
ATT_TIMESTAMP PHP type int; the return string will be the Unix time represented by the given TIMESTAMP type value
ATT_BINARY, ATT_NOSPEC PHP type string; each byte of the binary value will be represented by two characters, that represent the hexadecimal notation of the given byte
The byte with the ASCII code 32 (decadic) will be represented with the "20" substring; the byte with the ASCII code 13 (decadic) will be represented with the substring "0d"

Examples

Example 1: Pass two input client variables, the first is INT type, the second is VARCHAR type.

If we do not have an output variable in DAD, we can specify the hostvars parameter value as a constant of this array type.

wb_export_to_XML($connection,"*testdad","outfile.xml",NULL,
    array(
        // first variable name is number
        "number" => array(
            // type ATT_INT32, i.e. INT
            "type" => ATT_INT32,
            // input value is 123456
            "value" => 123456
        ),
        // second variable name is string
        "string" => array(
            // type ATT_STRING, i.e. VARCHAR
            "type" => ATT_STRING,
            // input value is "abcdefgh"
            "value" => "abcdefgh"
        )
    )
);

Example 2: Pass the input-output client variable of the NCLOB type.

If the output variable exists, we will have to enter the hostvars variable as a pointer to the array type variable, otherwise the client variable output value will be unreadable when the function is complete.

wb_set_client_encoding($connection, WB_ENC_UTF8);
$hostvars=array(
    // variable name is uniclob
    "uniclob" => array(
        // type ATT_TEXT
        "type" => ATT_TEXT,
        // it's Unicode CLOB
        "wide_char" => TRUE,
        // input value is this UTF-8 string (edited in UTF-8)
        "value" => "Testing.",
        // the output buffer will be 500 Unicode character long
        // if we don't specify the buffer length,
        // it'll be only as long as the input variable,
        // i.e. 13 characters
        "length" => 500,
        // it's an OUT variable
        "out" => TRUE
    )
);
wb_import_from_XML($connection,"*importdad","infile.xml",$hostvars);
// we read the output value of this client variable (UTF-8 string) as follows
echo $hostvars["uniclob"]["value"];

Example 3: Pass the input-output client variable of the NCLOB type.

If you pass the input-output variable values in PHP variables, you can specify the hostvars parameter as an array type constant. The output values of the client variables will be written into the corresponding PHP variables. However, you must set the REFERENCE to the PHP variable, otherwise the output parameter value will be written to a field and not to the variable (the field is destroyed).

// the client variable value is in the $uniclob_value PHP variable
wb_import_from_XML($connection,"*importdad","infile.xml",
    array(
      // proměnná se jmenuje uniclob
      "uniclob" => array(
          // variable name is uniclob
          "type" => ATT_CLOB,
          // it's Unicode CLOB
          "wide_char" => TRUE,
          // input parameter is in the PHP variable
          // variable is set by a reference!!!
          "value" => &$uniclob_value,
          // the output buffer will be 500 Unicode character long
          "length" => 500,
          // it's an OUT variable
          "out" => TRUE
      )
    )
);
// the output value of the client variable (UTF-8 string) is in the PHP variable
echo $uniclob_value;

Viz