Xbasic

argument_add_array_argument Function

Syntax

V argument_add_array_argument(SQL::Arguments args ,C argName ,C argType ,C argValues )

Arguments

argsSQL::Arguments

The object that you want to add an argument array or update an existing argument array.

argNameCharacter

The name of the argument array to add to the args object.

argTypeCharacter

The argument type. For example, "C" for "character" or "N" for "numeric".

argValuesCharacter

A CR-LF delimited list of values.

Description

Adds or updates and array argument to an SQL::Arguments object. The SQL::Arguments object can be populated with argument arrays (typically used when passing values to a SQL query that uses an IN clause).

Example

dim args as SQL::Arguments 
dim cities as c 
cities = <<%txt%
London
Seattle
Madrid
%txt%
argument_add_array_argument(args,"cities","C",cities)

dim cn as SQL::Connection

? cn.open("::Name::AADemo-Northwind")
= .T.

? cn.execute("SELECT CustomerID, CompanyName, City FROM customers WHERE City IN (:cities)",args)
= .T.

dim json as c 
json = cn.resultSet.ToJSON()

? convert_utf8_to_acp(json)
= [
{"CustomerID" : "AROUT", "CompanyName" : "Around the Horn", "City" : "London"},
{"CustomerID" : "BOLID", "CompanyName" : "Bólido Comidas preparadas", "City" : "Madrid"},
{"CustomerID" : "BSBEV", "CompanyName" : "B's Beverages", "City" : "London"},
{"CustomerID" : "CONSH", "CompanyName" : "Consolidated Holdings", "City" : "London"},
{"CustomerID" : "EASTC", "CompanyName" : "Eastern Connection", "City" : "London"},
{"CustomerID" : "FISSA", "CompanyName" : "FISSA Fabrica Inter. Salchichas S.A.", "City" : "Madrid"},
{"CustomerID" : "NORTS", "CompanyName" : "North\/South", "City" : "London"},
{"CustomerID" : "ROMEY", "CompanyName" : "Romero y tomillo", "City" : "Madrid"},
{"CustomerID" : "SEVES", "CompanyName" : "Seven Seas Imports", "City" : "London"},
{"CustomerID" : "WHITC", "CompanyName" : "White Clover Markets", "City" : "Seattle"}
]

The next example demonstrates creating an array of numeric values:

dim args as sql::Arguments
dim ids as C
ids =<<%txt%
2
3
5
6
%txt%
argument_add_array_argument(args,"ids","N",ids)

dim cn as sql::Connection
? cn.open("::Name::AADemo-Northwind")
= .T.

? cn.execute("SELECT * FROM Products where ProductID IN (:ids)",args)
= .T.

? cn.ResultSet.toJSON()
= [
{"ProductID" : "2", "ProductName" : "Chang", "SupplierID" : "1", "CategoryID" : "1", "QuantityPerUnit" : "24 - 12 oz bottles", "UnitPrice" : "19", "UnitsInStock" : "17", "UnitsOnOrder" : "40", "ReorderLevel" : "25", "Discontinued" : "F"},
{"ProductID" : "3", "ProductName" : "Aniseed Syrup", "SupplierID" : "1", "CategoryID" : "2", "QuantityPerUnit" : "12 - 550 ml bottles", "UnitPrice" : "10", "UnitsInStock" : "13", "UnitsOnOrder" : "70", "ReorderLevel" : "25", "Discontinued" : "F"},
{"ProductID" : "5", "ProductName" : "Chef Anton's Gumbo Mix", "SupplierID" : "2", "CategoryID" : "2", "QuantityPerUnit" : "36 boxes", "UnitPrice" : "21.35", "UnitsInStock" : "0", "UnitsOnOrder" : "0", "ReorderLevel" : "0", "Discontinued" : "T"},
{"ProductID" : "6", "ProductName" : "Grandma's Boysenberry Spread", "SupplierID" : "3", "CategoryID" : "2", "QuantityPerUnit" : "12 - 8 oz jars", "UnitPrice" : "25", "UnitsInStock" : "120", "UnitsOnOrder" : "0", "ReorderLevel" : "25", "Discontinued" : "F"}
]

See Also