Platforms to show: All Mac Windows Linux Cross-Platform

Back to SQLCommandMBS class.

Previous items

SQLCommandMBS.Prepare

Type Topic Plugin Version macOS Windows Linux iOS Targets
method SQL MBS SQL Plugin 9.3 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Prepares command before execution.

Prepare method compiles the command, but does not execute it. The method detects syntax errors in command text and verifies the existence of database objects.

Execute method calls Prepare method implicitly if needed, therefore you don't have to call it explicitly.

SQLCommandMBS.setCommandText(SQLCommand as string, CommandType as Integer = 0)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method SQL MBS SQL Plugin 9.3 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Sets the command text.
Example
dim s as new SQLCommandMBS

s.setCommandText "select * from test"

MsgBox s.CommandText

SQLCommand: A string which represents command text string (an SQL statement or a stored procedure name).
CommandType: The type of command like kCommandTypeUnknown, kCommandTypeSQLStatement, kCommandTypeSQLStatementRaw or kCommandTypeStoredProcedure.

It's not necessary to set a command type explicitly, because it is defined automatically in terms of command text string. But if you still have any reason to do it, use one of the kCommandType* constants. To get command type use CommandType method.

Some examples using this method:

SQLCommandMBS.SetParameters(Params as dictionary)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method SQL MBS SQL Plugin 16.4 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Sets the parameters based on the keys and values in the dictionary.
Example
dim con as SQLConnectionMBS // your connection
dim pic as picture // some picture

// get picture data
dim jpegData as MemoryBlock = pic.GetData(Picture.FormatJPEG, 80)

// parse a SQL command
dim sql as string = "Insert into BlobTest(name, image) values (:name, :image)"
dim cmd as new SQLCommandMBS(con, sql)

dim d as new Dictionary
// set by param index
d.Value(0) = "test.jpg"
// set by param name
d.Value("image") = jpegData

// set all parameters together
cmd.SetParameters d
cmd.Execute

Keys can be String, Text or numeric types. Text and String are used to pick parameters by name. Numeric values are used to pick parameter by index (zero based).
MemoryBlock and Strings without text encoding are converted to byte values (BLOB).
Texts and Strings with encoding are converted to text values.
Raises exceptions if you pass anything which is not recognized.
Other types are translated as good as possible.

Raises OutOfBoundsException exception if index parameter is out of range.

SQLCommandMBS.Value(index as Integer) as SQLValueReadMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method SQL MBS SQL Plugin 16.1 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Returns the value specified by its position in the result set.
Example
dim c as SQLCommandMBS // your command object

// get field by name
dim f1 as SQLValueReadMBS = c.Value("FirstName")

// get field by Index
dim f2 as SQLValueReadMBS = c.Value(1)

You can use Value() to get values for normal or cached result sets.

index: A one-based field number in a result set.

Use Value method to access a field by its name or position in the result set.
For Cached result sets, please use Value() function to get values.

Using an index smaller than 1 and greater then the value returned by FieldCount method will result in a failed assertion.

A set of SAField objects creates implicitly after the command execution if the result set exists. SAField object contains full information about a column: name, type, size, value.

Raises OutOfBoundsException exception if index parameter is out of range.

See also:

SQLCommandMBS.Value(name as string) as SQLValueReadMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method SQL MBS SQL Plugin 16.1 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Returns the value specified by its name in the result set.
Example
dim c as SQLCommandMBS // your command object

// get value by name
dim f1 as SQLValueReadMBS = c.Value("FirstName")

// get value by Index
dim f2 as SQLValueReadMBS = c.Value(1)

You can use Value() to get values for normal or cached result sets.

name: A string that represents a name of the requested field.

Returns a reference to a SAValueRead object.

Use Value method to access a field by its name or position in the result set.
Using a non-existent field name will throw an exception.

A set of SAField objects creates implicitly after the command execution if the result set exists.SAField object contains full information about a column: name, type, size, value.

See also:

Previous items

The items on this page are in the following plugins: MBS SQL Plugin.


The biggest plugin in space...