Module _cubrid :: Class cursor
[hide private]
[frames] | no frames]

Class cursor

object --+
         |
        cursor

Cursor class.

Instance Methods [hide private]
 
__init__(...)
x.__init__(...) initializes x; see help(type(x)) for signature
a new object with type S, a subtype of T
__new__(T, S, ...)
 
__repr__(x)
repr(x)
 
_set_charset_name(...)
Only used internally.
 
affected_rows()
get the number of rows affected by the SQL sentence (INSERT, DELETE, UPDATE).
 
bind_lob(n, lob)
bind BLOB/CLOB type in prepare() variable.
 
bind_param(index, string, bind_type)
This function is used to bind values in prepare() variable.
 
bind_set(index, data)
bind_set LIST/SET/MULTISET data.
 
close()
Close the current cursor object.
 
data_seek(n)
move the cursor based on the original position.
 
execute(option=..., max_col_size=...)
Executes a prepared Query.
 
fetch_lob(col, lob)
get BLOB/CLOB data out from the database server.
 
fetch_row()
get a single row from the query result.
 
next_result()
get results of next query if CUBRID_EXEC_QUERY_ALL flag is set upon execute().
 
num_fields()
get the number of columns from the query result.
 
num_rows()
get the number of rows from the query result.
 
prepare(sql)
This function creates a prepared statement.
 
result_info(n)
returns a sequence of 15-item sequences.
 
row_seek(offset)
move the current cursor based on current cursor position.
 
row_tell(...)
get the current position of the cursor.

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __reduce__, __reduce_ex__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties [hide private]
  description
description
  rowcount
row count

Inherited from object: __class__

Method Details [hide private]

__init__(...)
(Constructor)

 

x.__init__(...) initializes x; see help(type(x)) for signature

Overrides: object.__init__

__new__(T, S, ...)

 
Returns: a new object with type S, a subtype of T
Overrides: object.__new__

__repr__(x)
(Representation operator)

 

repr(x)

Overrides: object.__repr__

_set_charset_name(...)

 

Only used internally. This function should not be used by user.

affected_rows()

 

get the number of rows affected by the SQL sentence (INSERT, DELETE, UPDATE).

Return values:

 Success: Number of rows affected by the SQL sentence
 Failure: -1

bind_lob(n, lob)

 

bind BLOB/CLOB type in prepare() variable.

Parameters:

 index: string, actual value for binding
 lob: LOB Object

Example:

 import _cubrid
 con = _cubrid.connect('CUBRID:localhost:33000:demodb:::', 'public')
 cur = con.cursor()
 
 cur.prepare('create table test_blob(image BLOB)')
 cur.execute()
 cur.prepare('create table test_clob(image CLOB)')
 cur.execute()
 
 lob = con.lob()
 
 cur.prepare('insert into test_blob values (?)')
 lob.imports('123.jpg') # or lob.imports('123.jpg', 'B')
 cur.bind_lob(1, lob)
 cur.execute()
 lob.close()
 
 cur.prepare('insert into test_clob values (?)')
 lob.imports('123.jpg', 'C')
 cur.bind_lob(1, lob)
 cur.execute()
 lob.close()
 
 cur.close()
 con.close()

bind_param(index, string, bind_type)

 

This function is used to bind values in prepare() variable. You can pass any type as string, except BLOB/CLOB type. In CUBRID shard envrioment, the bind_type must be included in the bind_param function. The following shows the types of substitute values:

 CHAR
 STRING
 NCHAR
 VARCHAR
 NCHAR VARYING
 BIT
 BIT VARYING
 SHORT
 INT
 NUMERIC
 FLOAT
 DOUBLE
 TIME
 DATE
 TIMESTAMP
 OBJECT
 BLOB
 CLOB
 NULL

Parameters:

 index: int, index for binding
 value: string, actual value for binding
 bind_type(optional):column type of database 

bind_set(index, data)

 
bind_set LIST/SET/MULTISET data. To use this function.
index:actual value for binding
data:tuple object 

    Example::
    con = _cubrid.connect('CUBRID:localhost:30000:demodb:dba::')
    c = con.cursor()
    s = con.set()
    value = ('1','2')
    s.imports(value ,CUBRIDdb.CCI_U_TYPE_INT)
    c.prepare('''INSERT INTO set_tbl_int VALUES(?);''')
    c.bind_set(1,s)
    c.execute()
    con.commit()
    c.close()
    con.close()

data_seek(n)

 

move the cursor based on the original position.

offset: int, number of units you want to move the cursor.

execute(option=..., max_col_size=...)

 

Executes a prepared Query. A option can be used when retrieving the query result from the server. A option can be classified as synchronous or asynchronous. If the option is set to CUBRID_EXEC_QUERY_ALL, a synchronous mode(sync_mode) is used to retrieve query results immediately after executing prepared queries. If it is set to CUBRID_EXEC_ASYNC, an asynchronous mode (async_mode) is used to retrieve the result immediately each time a query result is created. The option is set to CUBRID_EXEC_QUERY_ALL by default, and in such cases the following rules are applied:

  • The return value is the result of the first query.
  • If an error occurs in any query, the execution is processed as a failure.
  • For a query composed of in a query composed of q1 q2 q3 if an error occurs in q2 after q1 succeeds the execution, the result of q1 remains valid. That is, the previous successful query executions are not rolled back when an error occurs.
  • If a query is executed successfully, the result of the second query can be obtained using next_result().

max_col is a value that is used to determine the size of the column to be transferred to the client when the type of the column of the prepared query is CHAR, VARCHAR, NCHAR, VARNCHAR, BIT or VARBIT. If it is set to 0, all data is transferred.

Parameters:

 option: Exec option, option maybe the following values:
   CUBRID_EXEC_ASYNC
   CUBRID_EXEC_QUERY_ALL
   CUBRID_EXEC_QUERY_INFO
   CUBRID_EXEC_ONLY_QUERY_PLAN
   CUBRID_EXEC_THREAD

Return values:

 SELECT: Returns the number of results in sync mode,
         returns 0 in asynchronism mode.
 INSERT, UPDATE: Returns the number of tuples reflected.
 Others queries: 0

fetch_lob(col, lob)

 

get BLOB/CLOB data out from the database server. You need to specify which column is lob type.

Parameters:

 col: int, the column of LOB
 lob: LOB object, to process LOB data.

Example:

 import _cubrid
 con = _cubrid.connect('CUBRID:localhost:33000:demodb:::', 'public')
 cur = con.cursor()
 cur.prepare('select * from test_lob')
 cur.execute()
 lob = con.lob()
 cur.fetch_lob(1, lob)
 lob.close()
 cur.close()
 con.close()

fetch_row()

 

get a single row from the query result. The cursor automatically moves to the next row after getting the result.

Example:

 import _cubrid
 con = _cubrid.connect('CUBRID:localhost:33000:demodb:::', 'public')
 cur = con.cursor()
 cur.prepare('select * from test_cubrid')
 cur.execute()
 row = cur.fetch_row()
 while row:
   print row
   row = cur.fetch_row()
 cur.close()
 con.close()

next_result()

 

get results of next query if CUBRID_EXEC_QUERY_ALL flag is set upon execute(). If next result is executed successfully, the database is updated with the information of the current query.

num_fields()

 

get the number of columns from the query result. It can only be used when the query executed is a select sentence.

num_rows()

 

get the number of rows from the query result. It can only be used when the query executed is a select sentence.

prepare(sql)

 

This function creates a prepared statement. A prepared statement is a server-side object that can be used to optimize performance. You can use this statement effectively to execute repeatedly or to process long data. Only a single statement can be used. The SQL statement can contain zero or more question mark (?) parameter markers for which real values will be substituted when the statement is executed. Add a parameter when you bind a value in the VALUES clause of INSERT statement or in the WHERE clause.

sql: string, the sql statement you want to execute.

result_info(n)

 

returns a sequence of 15-item sequences. Each of these sequence contails information describing one result column:

(datatype,
 scale,
 precision,
 col_name,
 attr_name,
 class_name,
 not_null,
 default_value,
 auto_increment,
 unique_key,
 primary_key,
 foreign_key,
 reverse_index,
 reverse_unique,
 shared)

values of datatype will map the following:

 char                 1
 string,varchar       2
 nchar                3
 varnchar             4
 bit                  5
 varbit               6
 numeric              7
 int                  8
 short                9
 monetary             10
 float                11
 double               12
 date                 13
 time                 14
 timestamp            15
 object               19
 set                  32
 multiset             64
 sequence             96

This function will return none if there is no result set. If user not specifies the parameter row, it will return all column's information. If user specify row, it will return the specified column's information.

row: int, the column you want to get the information.

Example:

 import _cubrid
 con = _cubrid.connect('CUBRID:localhost:33000:demodb:::', 'public')
 cur = con.cursor()
 cur.prepare('select * from test_cubrid')
 cur.execute()
 infos = cur.result_info()
 for info in infos:
     print info
 print cur.result_info(1)
 cur.close()
 con.close()

row_seek(offset)

 

move the current cursor based on current cursor position. If give a positive number, it will move forward. If you give a negative number, it will move back.

offset: int, relative location that you want to move.