|
@@ 310-337 (lines=28) @@
|
| 307 |
|
return ret |
| 308 |
|
|
| 309 |
|
# ------------------------------------------------------------------------------------------------------------------ |
| 310 |
|
def execute_sp_singleton1(self, sql: str, *params) -> object: |
| 311 |
|
""" |
| 312 |
|
Executes a stored procedure that selects 1 row with 1 column. Returns the value of the selected column. |
| 313 |
|
|
| 314 |
|
:param str sql: The SQL call the the stored procedure. |
| 315 |
|
:param iterable params: The arguments for the stored procedure. |
| 316 |
|
|
| 317 |
|
:rtype: object |
| 318 |
|
""" |
| 319 |
|
cursor = self._connection.cursor() |
| 320 |
|
if params: |
| 321 |
|
cursor.execute(sql, params) |
| 322 |
|
else: |
| 323 |
|
cursor.execute(sql) |
| 324 |
|
portal = self._connection.cursor(cursor.fetchone()[0]) |
| 325 |
|
rows = portal.fetchall() |
| 326 |
|
row_count = len(rows) |
| 327 |
|
if row_count == 1: |
| 328 |
|
ret = rows[0][0] |
| 329 |
|
else: |
| 330 |
|
ret = None # Keep our IDE happy. |
| 331 |
|
portal.close() |
| 332 |
|
cursor.close() |
| 333 |
|
|
| 334 |
|
if len(rows) != 1: |
| 335 |
|
raise ResultException('1', row_count, sql) |
| 336 |
|
|
| 337 |
|
return ret |
| 338 |
|
|
| 339 |
|
# ------------------------------------------------------------------------------------------------------------------ |
| 340 |
|
def execute_sp_table(self, sql: str, *params) -> int: |
|
@@ 253-280 (lines=28) @@
|
| 250 |
|
return ret |
| 251 |
|
|
| 252 |
|
# ------------------------------------------------------------------------------------------------------------------ |
| 253 |
|
def execute_sp_singleton0(self, sql: str, *params) -> object: |
| 254 |
|
""" |
| 255 |
|
Executes a stored procedure that selects 0 or 1 row with 1 column. Returns the value of selected column or None. |
| 256 |
|
|
| 257 |
|
:param str sql: The SQL call the the stored procedure. |
| 258 |
|
:param iterable params: The arguments for the stored procedure. |
| 259 |
|
|
| 260 |
|
:rtype: object |
| 261 |
|
""" |
| 262 |
|
cursor = self._connection.cursor() |
| 263 |
|
if params: |
| 264 |
|
cursor.execute(sql, params) |
| 265 |
|
else: |
| 266 |
|
cursor.execute(sql) |
| 267 |
|
portal = self._connection.cursor(cursor.fetchone()[0]) |
| 268 |
|
rows = portal.fetchall() |
| 269 |
|
row_count = len(rows) |
| 270 |
|
if row_count == 1: |
| 271 |
|
ret = rows[0][0] |
| 272 |
|
else: |
| 273 |
|
ret = None # Keep our IDE happy. |
| 274 |
|
portal.close() |
| 275 |
|
cursor.close() |
| 276 |
|
|
| 277 |
|
if not (row_count == 0 or row_count == 1): |
| 278 |
|
raise ResultException('0 or 1', row_count, sql) |
| 279 |
|
|
| 280 |
|
return ret |
| 281 |
|
|
| 282 |
|
# ------------------------------------------------------------------------------------------------------------------ |
| 283 |
|
def execute_singleton1(self, sql: str, *params) -> object: |