Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
from drizzle import libdrizzle as _libdrizzle
libdrizzle = _libdrizzle.Drizzle()
def connect(*args, **kwargs):
connection = Connection(*args, **kwargs)
return connection
class Connection:
def __init__(self, host=None, port=None, username=None, password=None, database=None): = host
self.port = port
self.username = username
self.password = password
self.database = database
self._drizzle_connection = None
def _connect(self):
self._drizzle_connection = libdrizzle.create_connection()
self._drizzle_connection.set_tcp(, self.port)
#self._drizzle_connection.set_auth(self.username, self.password)
def cursor(self):
return Cursor(self)
class Cursor:
def __init__(self, connection):
self._connection = connection
def connection(self):
return self._connection
def _drizzle_connection(self):
return self.connection._drizzle_connection
def execute(self, sql):
self._last_result = self._drizzle_connection.query(sql)
self._columns = [column for column in iter(self._last_result.read_column, None)]
# FIXME: self.description = ...
# FIXME: need to cleanup column/libdrizzle buffer stuff if called multiple times
def fetchall(self):
#rows = []
#for row_buffer in iter(self._last_result.buffer_row, None):
# row = []
# print row_buffer
# pos = 0
# for column in self._columns:
# # FIXME use named_tuple
# row.append(row_buffer[pos:pos+column.size()])
# pos += column.column_size()
# r.free_row(row_buffer)
# rows.append(row)
return [row for row in iter(self._last_result.row_next, None)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.