|
@ -14,7 +14,7 @@ from openerp import _, api, fields, models |
|
|
from openerp.exceptions import Warning as UserError |
|
|
from openerp.exceptions import Warning as UserError |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SQLRequestMixin(models.Model): |
|
|
|
|
|
|
|
|
class SQLRequestMixin(models.AbstractModel): |
|
|
_name = 'sql.request.mixin' |
|
|
_name = 'sql.request.mixin' |
|
|
|
|
|
|
|
|
_clean_query_enabled = True |
|
|
_clean_query_enabled = True |
|
@ -60,7 +60,7 @@ class SQLRequestMixin(models.Model): |
|
|
|
|
|
|
|
|
query = fields.Text( |
|
|
query = fields.Text( |
|
|
string='Query', required=True, help="You can't use the following words" |
|
|
string='Query', required=True, help="You can't use the following words" |
|
|
": DELETE, DROP, CREATE, INSERT, ALTER, TRUNCATE, EXECUTE, UPDATE") |
|
|
|
|
|
|
|
|
": DELETE, DROP, CREATE, INSERT, ALTER, TRUNCATE, EXECUTE, UPDATE.") |
|
|
|
|
|
|
|
|
state = fields.Selection( |
|
|
state = fields.Selection( |
|
|
string='State', selection=STATE_SELECTION, default='draft', |
|
|
string='State', selection=STATE_SELECTION, default='draft', |
|
@ -82,7 +82,7 @@ class SQLRequestMixin(models.Model): |
|
|
|
|
|
|
|
|
# Action Section |
|
|
# Action Section |
|
|
@api.multi |
|
|
@api.multi |
|
|
def button_clean_check_request(self): |
|
|
|
|
|
|
|
|
def button_validate_sql_expression(self): |
|
|
for item in self: |
|
|
for item in self: |
|
|
if item._clean_query_enabled: |
|
|
if item._clean_query_enabled: |
|
|
item._clean_query() |
|
|
item._clean_query() |
|
@ -198,7 +198,10 @@ class SQLRequestMixin(models.Model): |
|
|
self.env.cr.execute("SHOW server_version;") |
|
|
self.env.cr.execute("SHOW server_version;") |
|
|
res = self.env.cr.fetchone()[0].split('.') |
|
|
res = self.env.cr.fetchone()[0].split('.') |
|
|
minor_version = float('.'.join(res[:2])) |
|
|
minor_version = float('.'.join(res[:2])) |
|
|
return minor_version >= 9.3 |
|
|
|
|
|
|
|
|
if minor_version < 9.3: |
|
|
|
|
|
raise UserError(_( |
|
|
|
|
|
"Materialized View requires PostgreSQL 9.3 or greater but" |
|
|
|
|
|
" PostgreSQL %s is currently installed.") % (minor_version)) |
|
|
|
|
|
|
|
|
@api.multi |
|
|
@api.multi |
|
|
def _clean_query(self): |
|
|
def _clean_query(self): |
|
|