Switch to: V9V8V7V6V5

VSqlStatement Class: Bind Methods

Description:

After you got the VSqlStatement object you can set bound values (if needed).

Below you can see a group of similar methods to bind values of different types into the statement object. Internally they are stored as an array.

Please notice, that these methods index array from zero! If you are using ”:1” notation of SQL binding in a query, to avoid mistakes you can use the TIP shown in the example below, do “n-1” in code. Another way to specify placeholders is to use ”?”.

ValentinaDB allows binding to VSqlStatement many records. Usually, this is for INSERTs. See below multi-row methods section.

Example:

dim stmt1 as VSqlStatement = db.Prepare( "INSERT INTO T1 VALUES( :1, :2, :3 );" )
 
for i = 1 to 100
    stmt1.bind_int32 ( 1-1, 578 )
    stmt1.bind_null  ( 2-1 )
    stmt1.bind_string( 3-1, "Jason" )
 
    affectedRows = stmt1.SqlExecute()
next
dim stmt1 as VSqlStatement = db.Prepare( "INSERT INTO T1 VALUES( ?, ?, ? );" )
 
for i = 1 to 100
    stmt1.bind_int32 ( 0, 578 )
    stmt1.bind_null  ( 1 )
    stmt1.bind_string( 2, "Jason" )
 
    affectedRows = stmt1.SqlExecute()
next

See Also

Single-Row Methods

VSqlStatement.Bind_null

Declaration:

Bind_null( InIndex as Integer )

Description:

This method is to set “sql-null” value into the current binding row.

Parameters:

  • InIndex - zero-based value position in binding row.

Example:

stmt.Bind_null(0)

VSqlStatement.Bind_bool

Declaration:

Bind_bool( InIndex as Integer, inValue as Boolean )

Description:

This method is to set boolean value into the current binding row.

Parameters:

  • InIndex - zero-based value position in binding row.
  • InValue - value.

Example:

stmt.Bind_bool(0, true)

VSqlStatement.Bind_uint8

Declaration:

Bind_uint8( InIndex as Integer, inValue as Byte )

Description:

This method is to set byte value into the current binding row.

Parameters:

  • InIndex - zero-based value position in binding row.
  • InValue - value.

Example:

stmt.Bind_uint8(0, 'a')

VSqlStatement.Bind_uint16

Declaration:

Bind_uint16( InIndex as Integer, inValue as SmallUInt )

Description:

This method is to set smallUInt value into the current binding row.

Parameters:

  • InIndex - zero-based value position in binding row.
  • InValue - value.

Example:

stmt.Bind_uint16(0, 1)

VSqlStatement.Bind_int16

Declaration:

Bind_int16( InIndex as Integer, inValue as SmallInt )

Description:

This method is to set smallInt value into the current binding row.

Parameters:

  • InIndex - zero-based value position in binding row.
  • InValue - value.

Example:

stmt.Bind_int16(0, -1)

VSqlStatement.Bind_uint32

Declaration:

Bind_uint32( InIndex as Integer, inValue as UInteger )

Description:

This method is to set UInteger value into the current binding row.

Parameters:

  • InIndex - zero-based value position in binding row.
  • InValue - value.

Example:

stmt.Bind_uint32(0 , 1)

VSqlStatement.Bind_int32

Declaration:

Bind_int32( InIndex as Integer, inValue as Integer )

Description:

This method is to set Integer value into the current binding row.

Parameters:

  • InIndex - zero-based value position in binding row.
  • InValue - value.

Example:

stmt.Bind_int32(0, -1)

VSqlStatement.Bind_uint64

Declaration:

Bind_uint64( InIndex as Integer, inValue as BigUInt )

Description:

This method is to set BigUInt value into the current binding row.

Parameters:

  • InIndex - zero-based value position in binding row.
  • InValue - value.

Example:

stmt.Bind_uint64(0, 1)

VSqlStatement.Bind_int64

Declaration:

Bind_int64( InIndex as Integer, inValue as BigInt )

Description:

This method is to set BigInt value into the current binding row.

Parameters:

  • InIndex - zero-based value position in binding row.
  • InValue - value.

Example:

stmt.Bind_int64(0, -1)

VSqlStatement.Bind_float

Declaration:

Bind_float(InIndex as Integer, inValue as Float)

Description:

This method is to set Float value into the current binding row.

Parameters:

  • InIndex - zero-based value position in binding row.
  • InValue - value.

Example:

stmt.Bind_float(0, 1.1)

VSqlStatement.Bind_double

Declaration:

Bind_double( InIndex as Integer, inValue as Double )

Description:

This method is to set Double value into the current binding row.

Parameters:

  • InIndex - zero-based value position in binding row.
  • InValue - value.

Example:

stmt.Bind_double(0, 1.1)

VSqlStatement.Bind_string

Declaration:

Bind_string( InIndex as Integer, inValue as String )

Description:

This method is to set String value into the current binding row.

Parameters:

  • InIndex - zero-based value position in binding row.
  • InValue - value.

Example:

stmt.Bind_string(0, 'abc')

VSqlStatement.Bind_binary

Declaration:

Bind_binary( InIndex as Integer, inValue as ByteArray )

Description:

This method is to set binary value into the current binding row.

Parameters:

  • InIndex - zero-based value position in binding row.
  • InValue - value.

Example:

stmt.Bind_binary(0, value)

Multi-Row Methods

VSqlStatement.Init()

Declaration:

Init()	

Description:

This method is used for multi-row binding purposes. Call it to delete the previous binding matrix. You need this usually when writing loop, which reuse the same SqlStatement object.

Example:

//@ Prepare 2x2 binding matrix:
 
// The first binding row:
stmt.Bind_bool(0,true)
stmt.Bind_null(1)
 
// The second binding row:
stmt.AddBindRow()
stmt.Bind_bool(0,false)
stmt.Bind_null(1)
 
// Execute statement:
stmt.SqlExecute()
 
 
// ------------
//@ Prepare 3x2 binding matrix:
//
 
// Init statement to be able to set another multi/single-row binding:
stmt.Init()
 
// The first binding row:
stmt.Bind_bool(0,false)
stmt.Bind_null(1)
 
// The second binding row:
stmt.AddBindRow()
stmt.Bind_bool(0,true)
stmt.Bind_null(1)
 
// The third binding row:
stmt.AddBindRow()
stmt.Bind_bool(0,true)
stmt.Bind_null(1)
 
// Execute statement:
stmt.SqlExecute()

VSqlStatement.AddBindRow()

Declaration:

AddBindRow()

Description:

This method is used for multi-row binding purposes. Call it to add a new row to the binding matrix.

Example:

'
' Prepare 2x2 binding matrix:
'
 
' First binding row:
stmt.Bind_bool(0,true)
stmt.Bind_null(1)
 
' Second binding row:
stmt.AddBindRow()
stmt.Bind_bool(0,false)
stmt.Bind_null(1)
 
'
' Execute statement:
'
stmt.SqlExecute()

Example:

func( params )
 
    stmt = db.Prepare( "DELETE FROM T WHERE RecID = ?" )
 
    for( i = 1; i <= 10; ++i )
    { 
        RecID = ...
        stmt.Bind_int(0, RecID )
 
        if( i < 10 )
          stmt.AddBindRow()
    }
 
    stmt.SqlExecute()  // Delete 10 records at once.
 
end func