OmniSciDB  72c90bc290
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
heavydb.cursor.Cursor Class Reference

Public Member Functions

def __init__
 
def __iter__
 
def __enter__
 
def __exit__
 
def description
 
def result_set
 
def arraysize
 
def arraysize
 
def close
 
def execute
 
def executemany
 
def fetchone
 
def fetchmany
 
def fetchall
 
def setinputsizes
 
def setoutputsizes
 

Public Attributes

 connection
 
 rowcount
 

Private Attributes

 _description
 
 _arraysize
 
 _result
 
 _result_set
 

Detailed Description

A database cursor.

Definition at line 6 of file cursor.py.

Constructor & Destructor Documentation

def heavydb.cursor.Cursor.__init__ (   self,
  connection 
)

Definition at line 9 of file cursor.py.

9 
10  def __init__(self, connection):
11  # XXX: supposed to share state between cursors of the same connection
12  self.connection = connection
13  self.rowcount = -1
14  self._description = None
15  self._arraysize = 1
16  self._result = None
17  self._result_set = None
18  if connection:
19  connection.register_runtime_udfs()

Member Function Documentation

def heavydb.cursor.Cursor.__enter__ (   self)

Definition at line 25 of file cursor.py.

25 
26  def __enter__(self):
27  return self
def heavydb.cursor.Cursor.__exit__ (   self,
  exc_type,
  exc_val,
  exc_tb 
)

Definition at line 28 of file cursor.py.

References heavydb.cursor.Cursor.close(), ai.heavy.jdbc.HeavyAIResultSet.close(), Archive.close(), ai.heavy.jdbc.HeavyAIStatement.close(), heavydb.connection.Connection.close(), ai.heavy.jdbc.HeavyAIConnection.close(), and ai.heavy.jdbc.HeavyAIPreparedStatement.close().

28 
29  def __exit__(self, exc_type, exc_val, exc_tb):
30  self.close()

+ Here is the call graph for this function:

def heavydb.cursor.Cursor.__iter__ (   self)

Definition at line 20 of file cursor.py.

References heavydb.cursor.Cursor.result_set().

20 
21  def __iter__(self):
22  if self.result_set is None:
23  return iter([])
24  return self.result_set

+ Here is the call graph for this function:

def heavydb.cursor.Cursor.arraysize (   self)
The number of rows to fetch at a time with `fetchmany`. Default 1.

See Also
--------
fetchmany

Definition at line 54 of file cursor.py.

References heavydb.cursor.Cursor._arraysize.

Referenced by heavydb.cursor.Cursor.arraysize(), and heavydb.cursor.Cursor.fetchmany().

54 
55  def arraysize(self):
56  """The number of rows to fetch at a time with `fetchmany`. Default 1.
57 
58  See Also
59  --------
60  fetchmany
61  """
62  return self._arraysize

+ Here is the caller graph for this function:

def heavydb.cursor.Cursor.arraysize (   self,
  value 
)
Number of items to fetch with :func:`fetchmany`.

Definition at line 64 of file cursor.py.

References heavydb.cursor.Cursor._arraysize, heavydb.cursor.Cursor.arraysize(), and run_benchmark_import.type.

64 
65  def arraysize(self, value):
66  """Number of items to fetch with :func:`fetchmany`."""
67  if not isinstance(value, int):
68  raise TypeError(
69  "Value must be an integer, got {} instead".format(type(value))
70  )
71  self._arraysize = value

+ Here is the call graph for this function:

def heavydb.cursor.Cursor.close (   self)
Close this cursor.

Definition at line 72 of file cursor.py.

Referenced by heavydb.cursor.Cursor.__exit__().

72 
73  def close(self):
74  """Close this cursor."""
75  # TODO
76  pass

+ Here is the caller graph for this function:

def heavydb.cursor.Cursor.description (   self)
Read-only sequence describing columns of the result set.
Each column is an instance of `Description` describing

- name
- type_code
- display_size
- internal_size
- precision
- scale
- null_ok

We only use name, type_code, and null_ok; The rest are always ``None``

Definition at line 32 of file cursor.py.

References heavydb.cursor.Cursor._description.

32 
33  def description(self):
34  """
35  Read-only sequence describing columns of the result set.
36  Each column is an instance of `Description` describing
37 
38  - name
39  - type_code
40  - display_size
41  - internal_size
42  - precision
43  - scale
44  - null_ok
45 
46  We only use name, type_code, and null_ok; The rest are always ``None``
47  """
48  return self._description
def heavydb.cursor.Cursor.execute (   self,
  operation,
  parameters = None 
)
Execute a SQL statement.

Parameters
----------
operation: str
    A SQL query
parameters: dict
    Parameters to substitute into ``operation``.

Returns
-------
self : Cursor

Examples
--------
>>> c = conn.cursor()
>>> c.execute("select symbol, qty from stocks")
>>> list(c)
[('RHAT', 100.0), ('IBM', 1000.0), ('MSFT', 1000.0), ('IBM', 500.0)]

Passing in ``parameters``:

>>> c.execute("select symbol qty from stocks where qty <= :max_qty",
...           parameters={"max_qty": 500})
[('RHAT', 100.0), ('IBM', 500.0)]

Definition at line 77 of file cursor.py.

Referenced by heavydb.cursor.Cursor.executemany().

77 
78  def execute(self, operation, parameters=None):
79  """Execute a SQL statement.
80 
81  Parameters
82  ----------
83  operation: str
84  A SQL query
85  parameters: dict
86  Parameters to substitute into ``operation``.
87 
88  Returns
89  -------
90  self : Cursor
91 
92  Examples
93  --------
94  >>> c = conn.cursor()
95  >>> c.execute("select symbol, qty from stocks")
96  >>> list(c)
97  [('RHAT', 100.0), ('IBM', 1000.0), ('MSFT', 1000.0), ('IBM', 500.0)]
98 
99  Passing in ``parameters``:
100 
101  >>> c.execute("select symbol qty from stocks where qty <= :max_qty",
102  ... parameters={"max_qty": 500})
103  [('RHAT', 100.0), ('IBM', 500.0)]
104  """
105 
106  # https://github.com/omnisci/pymapd/issues/263
107  operation = operation.strip()
108 
109  if parameters is not None:
110  operation = str(_bind_parameters(operation, parameters))
111  self.rowcount = -1
112  try:
113  result = self.connection._client.sql_execute(
114  self.connection._session,
115  operation,
116  column_format=True,
117  nonce=None,
118  first_n=-1,
119  at_most_n=-1,
120  )
121  except T.TDBException as e:
122  raise _translate_exception(e) from e
123  self._description = _extract_description(result.row_set.row_desc)
124 
125  try:
126  self.rowcount = len(result.row_set.columns[0].nulls)
127  except IndexError:
128  pass
129 
130  self._result_set = make_row_results_set(result)
131  self._result = result
132  return self
def make_row_results_set
Definition: cursor.py:179
def _bind_parameters
Definition: _parsers.py:162
def _extract_description
Definition: _parsers.py:124

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

def heavydb.cursor.Cursor.executemany (   self,
  operation,
  parameters 
)
Execute a SQL statement for many sets of parameters.

Parameters
----------
operation: str
parameters: list of dict

Returns
-------
results: list of lists

Definition at line 133 of file cursor.py.

References LeafAggregator.execute(), DdlCommand.execute(), CreateForeignServerCommand.execute(), AlterForeignServerCommand.execute(), heavydb.cursor.Cursor.execute(), DropForeignServerCommand.execute(), CreateForeignTableCommand.execute(), DropForeignTableCommand.execute(), AlterTableAlterColumnCommand.execute(), AlterTableCommand.execute(), AlterForeignTableCommand.execute(), ShowForeignServersCommand.execute(), ShowCreateServerCommand.execute(), ShowTablesCommand.execute(), ShowTableDetailsCommand.execute(), ShowCreateTableCommand.execute(), ai.heavy.jdbc.HeavyAIStatement.execute(), ShowDatabasesCommand.execute(), ShowFunctionsCommand.execute(), ShowRuntimeFunctionsCommand.execute(), ShowTableFunctionsCommand.execute(), ShowRuntimeTableFunctionsCommand.execute(), ShowModelsCommand.execute(), ShowModelDetailsCommand.execute(), ShowModelFeatureDetailsCommand.execute(), EvaluateModelCommand.execute(), ShowDiskCacheUsageCommand.execute(), ShowUserDetailsCommand.execute(), ShowRolesCommand.execute(), ai.heavy.jdbc.HeavyAIPreparedStatement.execute(), RefreshForeignTablesCommand.execute(), heavydb.connection.Connection.execute(), CreatePolicyCommand.execute(), ShowPoliciesCommand.execute(), DropPolicyCommand.execute(), AlterDatabaseCommand.execute(), ReassignOwnedCommand.execute(), DdlCommandExecutor.execute(), Parser::DDLStmt.execute(), Parser::CreateTableStmt.execute(), Parser::CreateDataframeStmt.execute(), Parser::InsertIntoTableAsSelectStmt.execute(), Parser::CreateTableAsSelectStmt.execute(), Parser::DropTableStmt.execute(), Parser::TruncateTableStmt.execute(), Parser::OptimizeTableStmt.execute(), Parser::ValidateStmt.execute(), Parser::RenameDBStmt.execute(), Parser::RenameUserStmt.execute(), Parser::RenameTableStmt.execute(), Parser::RenameColumnStmt.execute(), Parser::AddColumnStmt.execute(), Parser::DropColumnStmt.execute(), Parser::AlterTableParamStmt.execute(), Parser::DumpTableStmt.execute(), Parser::RestoreTableStmt.execute(), Parser::CopyTableStmt.execute(), Parser::CreateRoleStmt.execute(), Parser::DropRoleStmt.execute(), Parser::GrantPrivilegesStmt.execute(), Parser::RevokePrivilegesStmt.execute(), Parser::ShowPrivilegesStmt.execute(), Parser::GrantRoleStmt.execute(), Parser::RevokeRoleStmt.execute(), Parser::ExportQueryStmt.execute(), Parser::CreateViewStmt.execute(), Parser::DropViewStmt.execute(), Parser::CreateDBStmt.execute(), Parser::DropDBStmt.execute(), Parser::CreateModelStmt.execute(), Parser::DropModelStmt.execute(), Parser::CreateUserStmt.execute(), Parser::AlterUserStmt.execute(), Parser::DropUserStmt.execute(), and Parser::InsertValuesStmt.execute().

134  def executemany(self, operation, parameters):
135  """Execute a SQL statement for many sets of parameters.
136 
137  Parameters
138  ----------
139  operation: str
140  parameters: list of dict
141 
142  Returns
143  -------
144  results: list of lists
145  """
146  results = [
147  list(self.execute(operation, params)) for params in parameters
148  ]
149  return results
def heavydb.cursor.Cursor.fetchall (   self)

Definition at line 164 of file cursor.py.

165  def fetchall(self):
166  return list(self)
def heavydb.cursor.Cursor.fetchmany (   self,
  size = None 
)
Fetch ``size`` rows from the results set.

Definition at line 157 of file cursor.py.

References heavydb.cursor.Cursor.arraysize(), and heavydb.cursor.Cursor.fetchone().

158  def fetchmany(self, size=None):
159  """Fetch ``size`` rows from the results set."""
160  if size is None:
161  size = self.arraysize
162  results = [self.fetchone() for _ in range(size)]
163  return [x for x in results if x is not None]

+ Here is the call graph for this function:

def heavydb.cursor.Cursor.fetchone (   self)
Fetch a single row from the results set

Definition at line 150 of file cursor.py.

References heavydb.cursor.Cursor.result_set().

Referenced by heavydb.cursor.Cursor.fetchmany().

151  def fetchone(self):
152  """Fetch a single row from the results set"""
153  try:
154  return next(self.result_set)
155  except StopIteration:
156  return None

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

def heavydb.cursor.Cursor.result_set (   self)

Definition at line 50 of file cursor.py.

References heavydb.cursor.Cursor._result_set.

Referenced by heavydb.cursor.Cursor.__iter__(), and heavydb.cursor.Cursor.fetchone().

50 
51  def result_set(self):
52  return self._result_set

+ Here is the caller graph for this function:

def heavydb.cursor.Cursor.setinputsizes (   self,
  sizes 
)

Definition at line 167 of file cursor.py.

168  def setinputsizes(self, sizes):
169  pass
def heavydb.cursor.Cursor.setoutputsizes (   self,
  size,
  column = None 
)

Definition at line 170 of file cursor.py.

171  def setoutputsizes(self, size, column=None):
172  pass
173 
174 
175 # -----------------------------------------------------------------------------
176 # Result Sets
177 # -----------------------------------------------------------------------------
178 

Member Data Documentation

heavydb.cursor.Cursor._arraysize
private

Definition at line 14 of file cursor.py.

Referenced by heavydb.cursor.Cursor.arraysize().

heavydb.cursor.Cursor._description
private

Definition at line 13 of file cursor.py.

Referenced by heavydb.cursor.Cursor.description(), and heavydb.cursor.Cursor.execute().

heavydb.cursor.Cursor._result
private

Definition at line 15 of file cursor.py.

Referenced by heavydb.cursor.Cursor.execute().

heavydb.cursor.Cursor._result_set
private

Definition at line 16 of file cursor.py.

Referenced by heavydb.cursor.Cursor.execute(), and heavydb.cursor.Cursor.result_set().

heavydb.cursor.Cursor.connection

Definition at line 11 of file cursor.py.

heavydb.cursor.Cursor.rowcount

Definition at line 12 of file cursor.py.

Referenced by heavydb.cursor.Cursor.execute().


The documentation for this class was generated from the following file: