Files
tryton/trytond/backend/database.py
T

175 lines
4.2 KiB
Python
Raw Normal View History

2014-12-02 12:54:01 +01:00
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
2009-02-04 15:29:28 +01:00
DatabaseIntegrityError = None
2009-02-06 10:26:38 +01:00
DatabaseOperationalError = None
2009-02-04 15:29:28 +01:00
2012-04-01 23:08:15 +02:00
2009-02-04 15:29:28 +01:00
class DatabaseInterface(object):
'''
Define generic interface for database connection
'''
2013-09-06 22:32:37 +02:00
flavor = None
IN_MAX = 1000
2009-02-04 15:29:28 +01:00
def __new__(cls, name=''):
2009-04-08 17:55:24 +02:00
return object.__new__(cls)
def __init__(self, name=''):
self.name = name
2009-02-04 15:29:28 +01:00
def connect(self):
'''
Connect to the database
:return: the database
'''
raise NotImplementedError
2009-02-04 15:29:28 +01:00
def get_connection(self, autocommit, readonly=False):
'''Retrieve a connection on the database
2009-02-04 15:29:28 +01:00
:param autocommit: a boolean to activate autocommit
:param readonly: a boolean to specify if the transaction is readonly
'''
raise NotImplementedError
def put_connection(self, connection, close=False):
'''Release the connection
:param close: if close is True the connection is discarded
2009-02-04 15:29:28 +01:00
'''
raise NotImplementedError
2009-02-04 15:29:28 +01:00
def close(self):
'''
Close all connection
'''
raise NotImplementedError
2009-02-04 15:29:28 +01:00
@classmethod
def create(cls, connection, database_name):
2009-02-04 15:29:28 +01:00
'''
Create a database
:param connection: the connection to the database
:param database_name: the new database name
2009-02-04 15:29:28 +01:00
'''
raise NotImplementedError
2009-02-04 15:29:28 +01:00
def drop(self, connection, database_name):
2009-02-04 15:29:28 +01:00
'''
Drop a database
:param connection: the connection to the database
2009-02-04 15:29:28 +01:00
:param database_name: the database name
'''
raise NotImplementedError
2009-02-04 15:29:28 +01:00
2009-02-05 16:44:38 +01:00
@staticmethod
def dump(database_name):
'''
Dump a database
:param database_name: the database name
:return: the dump
'''
raise NotImplementedError
2009-02-05 16:44:38 +01:00
@staticmethod
def restore(database_name, data):
'''
Restore a database
:param database_name: the database name
:param data: the data
:return: True if succeed
'''
raise NotImplementedError
2009-02-05 16:44:38 +01:00
def list(self):
2009-02-04 15:29:28 +01:00
'''
Get the list of database
:return: a list of database name
'''
raise NotImplementedError
2009-02-04 15:29:28 +01:00
def init(self):
2009-02-04 15:29:28 +01:00
'''
Initialize a database
'''
raise NotImplementedError
2009-02-04 15:29:28 +01:00
def test(self):
'''
Test if it is a Tryton database.
'''
raise NotImplementedError
2009-07-07 19:32:31 +02:00
def nextid(self, connection, table):
2009-07-07 19:32:31 +02:00
'''
Return the next sequenced id for a table.
:param connection: a connection on the database
2009-07-07 19:32:31 +02:00
:param table: the table name
:return: an integer
'''
def setnextid(self, connection, table, value):
2009-07-07 19:32:31 +02:00
'''
Set the current sequenced id for a table.
:param connection: a connection on the database
2009-07-07 19:32:31 +02:00
:param table: the table name
'''
def currid(self, connection, table):
2009-07-07 19:32:31 +02:00
'''
Return the current sequenced id for a table.
:param connection: a connection on the database
2009-07-07 19:32:31 +02:00
:param table: the table name
:return: an integer
'''
def update_auto_increment(self, connection, table, value):
2009-07-07 19:32:31 +02:00
'''
Update auto_increment value of table
2009-07-07 19:32:31 +02:00
:param connection: a connection on the database
:param table: the table name
:param value: the auto_increment value
2009-07-07 19:32:31 +02:00
'''
pass
2009-07-07 19:32:31 +02:00
@classmethod
def lock(cls, connection, table):
2009-07-07 19:32:31 +02:00
'''
2010-02-25 16:43:04 +01:00
Lock the table
2009-07-07 19:32:31 +02:00
:param connection: a connection on the database
2010-02-25 16:43:04 +01:00
:param table: the table name
2009-07-07 19:32:31 +02:00
'''
raise NotImplementedError
def has_constraint(self):
'''
Return True if database handle constraint.
:return: a boolean
'''
raise NotImplementedError
2009-09-07 15:18:17 +02:00
2011-08-21 10:20:23 +02:00
def has_returning(self):
'''
Return True if database implements RETURNING clause in INSERT or UPDATE
statements.
:return: a boolean
'''
return False
2015-07-28 08:04:29 +02:00
def has_multirow_insert(self):
'Return True if database supports multirow insert'
return False