[Fix]: Add header feature in latest v14
parent
0b51e7c634
commit
ce8f42e841
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
{
|
{
|
||||||
"name": "SQL Request Abstract",
|
"name": "SQL Request Abstract",
|
||||||
"version": "14.0.1.0.0",
|
"version": "14.0.1.0.1",
|
||||||
"author": "GRAP,Akretion,Odoo Community Association (OCA)",
|
"author": "GRAP,Akretion,Odoo Community Association (OCA)",
|
||||||
"maintainers": ["legalsylvain"],
|
"maintainers": ["legalsylvain"],
|
||||||
"website": "https://github.com/OCA/server-tools",
|
"website": "https://github.com/OCA/server-tools",
|
||||||
|
|
|
@ -117,6 +117,7 @@ class SQLRequestMixin(models.AbstractModel):
|
||||||
rollback=True,
|
rollback=True,
|
||||||
view_name=False,
|
view_name=False,
|
||||||
copy_options="CSV HEADER DELIMITER ';'",
|
copy_options="CSV HEADER DELIMITER ';'",
|
||||||
|
header=False,
|
||||||
):
|
):
|
||||||
"""Execute a SQL request on the current database.
|
"""Execute a SQL request on the current database.
|
||||||
|
|
||||||
|
@ -143,6 +144,9 @@ class SQLRequestMixin(models.AbstractModel):
|
||||||
:param copy_options: (str) mentions extra options for
|
:param copy_options: (str) mentions extra options for
|
||||||
"COPY request STDOUT WITH xxx" request.
|
"COPY request STDOUT WITH xxx" request.
|
||||||
(Ignored if @mode != 'stdout')
|
(Ignored if @mode != 'stdout')
|
||||||
|
:param header: (boolean) if true, the header of the query will be
|
||||||
|
returned as first element of the list if the mode is fetchall.
|
||||||
|
(Ignored if @mode != fetchall)
|
||||||
|
|
||||||
..note:: The following exceptions could be raised:
|
..note:: The following exceptions could be raised:
|
||||||
psycopg2.ProgrammingError: Error in the SQL Request.
|
psycopg2.ProgrammingError: Error in the SQL Request.
|
||||||
|
@ -190,6 +194,9 @@ class SQLRequestMixin(models.AbstractModel):
|
||||||
self.env.cr.execute(query)
|
self.env.cr.execute(query)
|
||||||
if mode == "fetchall":
|
if mode == "fetchall":
|
||||||
res = self.env.cr.fetchall()
|
res = self.env.cr.fetchall()
|
||||||
|
if header:
|
||||||
|
colnames = [desc[0] for desc in self.env.cr.description]
|
||||||
|
res.insert(0, colnames)
|
||||||
elif mode == "fetchone":
|
elif mode == "fetchone":
|
||||||
res = self.env.cr.fetchone()
|
res = self.env.cr.fetchone()
|
||||||
finally:
|
finally:
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
* Florian da Costa <florian.dacosta@akretion.com>
|
* Florian da Costa <florian.dacosta@akretion.com>
|
||||||
* Sylvain LE GAL (https://twitter.com/legalsylvain)
|
* Sylvain LE GAL (https://twitter.com/legalsylvain)
|
||||||
* Alfadil Tabar (alfadil.tabar@gmail.com)
|
* Alfadil Tabar (alfadil.tabar@gmail.com)
|
||||||
|
* Helly kapatel <helly.kapatel@initos.com>
|
||||||
|
|
Loading…
Reference in New Issue