comet.CQuery

class comet.CQuery

This section describes all functions for the comet.CQuery class.

Methods

CQuery.send(command)

Send an SQL instruction or parts of an SQL instruction. The SQL instructions should contain placeholders in place of input values. Placeholders for input values can be specified in two forms :

  • ?

  • :1, :2, …

The first format is certainly the easier to use, but input values have be connected in the sequence of their application. If this is not possible, the second format can be used, input values will then be connected according to the numbering.

If strings are connected, no quotations marks need be inserted around the value placeholders. It is likewise not necessary to mask quotation marks in the strings.

All instructions sent with send are collected in the query and executed with execute() as one instruction. Following the execution of the instruction, the instruction buffer in the query is emptied. The connections to the entry values are likewise deleted following execution.

Parameters

command (str) – Instruction

Return type

None

Raises
Available

CScript

query::send

CQuery.input(value)

Connect an input variable to the corresponding placeholder in the command.

Parameters

value (int | float | str) – The value to connect.

Return type

None

Raises
Available

CScript

query::input

CQuery.output(type)

Define the output type for the next column of a select command. The output types must be given in the same order as the columns are returned from executing the command.

The provided types determine the types in the result tuple from fetch()

It is not necessary to define all output columns, but if you want to receive the results of the n-th column, all the preceding n-th columns must be defined.

Parameters

type (int) – The output type of the next column. One of Basic types

Return type

None

Raises
Available

CScript

query::output

CQuery.execute(replaceBindings=True)

Send all command parts as one instruction. All value placeholders in the command are replaced by the defined input value and the command is executed. After the command is executed, the command buffer is emptied and all connections to the input values are deleted.

Parameters

replaceBindings (bool) –

Replace placeholder markers before executing?

  • True: Yes (recommended)

  • False No.

    This value is used in SOAP connections only.

    Possible bound values from previous calls to input() are ignored in this case.

Return type

None

Raises
Available

CScript

query::exec

CQuery.fetch()

Fetch the next line of the results of the command. This command is to be called in a loop, after each command from which a result is expected, until it returns False. After the last data has been fetched, the query can be used for the processing of another command.

Returns

The loaded data from the command or None when no data is available.

When the result is not None, the entries are returned in the order of the selected columns of the command as a list of tuples.

Types in the tuples depend on the values provided by output():

Return type

list[tuple] | None

Raises

CometError – On internal error

Available

CQuery.commit(message='')

Confirm the changes of this query.

Parameters

message (str) – Description for the command

Return type

None

Raises
Available

CScript

query::commit

CQuery.rollback(message='')

Rollback the changes of this query.

Parameters

message (str) – Description for the command

Return type

None

Raises
Available

CScript

query::rollback

CQuery.getCommand(replaceBindings=False)

Get the completed command which has been send() to this query but not yet executed.

Parameters

replaceBindings (bool) –

Replace placeholder markers inside the command by their current values?

  • False: No

  • True: Yes.

    Replacing can only be done for placeholder marks already bound to a value by calls to input()

Returns

The prepared command

Return type

str

Raises
Available

CScript

query::get_command

CQuery.getParent()

Get the parent data connection this query was created by.

Returns

The parent data connection

Return type

CSQL | CSOAP

Available