|
22 | 22 | from .exceptions import ProgrammingError
|
23 | 23 | from distutils.version import StrictVersion
|
24 | 24 | import warnings
|
| 25 | +from datetime import datetime |
25 | 26 |
|
26 | 27 | BULK_INSERT_MIN_VERSION = StrictVersion("0.42.0")
|
27 | 28 |
|
@@ -53,8 +54,35 @@ def execute(self, sql, parameters=None, bulk_parameters=None):
|
53 | 54 | self._result = self.connection.client.sql(sql, parameters,
|
54 | 55 | bulk_parameters)
|
55 | 56 | if "rows" in self._result:
|
| 57 | + if "col_types" in self._result: |
| 58 | + col_types = self._result["col_types"] |
| 59 | + tmp_data = self._result["rows"] |
| 60 | + |
| 61 | + rows_to_convert = self._get_rows_to_convert_to_date(col_types) |
| 62 | + tmp_data = self._convert_dates_to_datetime(tmp_data, rows_to_convert) |
| 63 | + |
| 64 | + self._result["rows"] = tmp_data |
| 65 | + |
56 | 66 | self.rows = iter(self._result["rows"])
|
57 | 67 |
|
| 68 | + @staticmethod |
| 69 | + def _get_rows_to_convert_to_date(col_types): |
| 70 | + return [True if col_type == 11 or col_type == 15 else False for col_type in col_types] |
| 71 | + |
| 72 | + @staticmethod |
| 73 | + def _date_to_datetime(row, rows_to_convert): |
| 74 | + return list( |
| 75 | + map(lambda x, y: |
| 76 | + datetime.fromtimestamp(float(str(x)[0:10])) if y else x, |
| 77 | + row, |
| 78 | + rows_to_convert)) |
| 79 | + |
| 80 | + def _convert_dates_to_datetime(self, rows, rows_to_convert): |
| 81 | + return list( |
| 82 | + map(lambda x: |
| 83 | + self._date_to_datetime(x, rows_to_convert), |
| 84 | + rows)) |
| 85 | + |
58 | 86 | def executemany(self, sql, seq_of_parameters):
|
59 | 87 | """
|
60 | 88 | Prepare a database operation (query or command) and then execute it
|
|
0 commit comments