Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Metabase
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Engineering Digital Service
Metabase
Commits
b652824a
Commit
b652824a
authored
9 years ago
by
Cam Saul
Browse files
Options
Downloads
Patches
Plain Diff
fix setting the timezone in Native SQL queries
parent
d1d4133f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/metabase/driver/generic_sql.clj
+2
-1
2 additions, 1 deletion
src/metabase/driver/generic_sql.clj
src/metabase/driver/generic_sql/native.clj
+2
-14
2 additions, 14 deletions
src/metabase/driver/generic_sql/native.clj
with
4 additions
and
15 deletions
src/metabase/driver/generic_sql.clj
+
2
−
1
View file @
b652824a
...
...
@@ -11,7 +11,8 @@
(
defrecord
SqlDriver
[
column->base-type
connection-details->connection-spec
database->connection-details
sql-string-length-fn
]
sql-string-length-fn
timezone->set-timezone-sql
]
IDriver
;; Connection
(
can-connect?
[
this
database
]
...
...
This diff is collapsed.
Click to expand it.
src/metabase/driver/generic_sql/native.clj
+
2
−
14
View file @
b652824a
...
...
@@ -10,18 +10,6 @@
[
metabase.driver.generic-sql.util
:refer
:all
]
[
metabase.models.database
:refer
[
Database
]]))
(
def
^
:dynamic
*timezone->set-timezone-sql*
" This function is called whenever `timezone` is specified in a native query, at the beginning of
the DB transaction.
If implemented, it should take a timestamp like `\"US/Pacific\"` and return a SQL
string that can be executed to set the timezone within the context of a transaction,
e.g. `\"SET LOCAL timezone to 'US/Pacific'\"`.
Because not all DB engines support timestamps (e.g., H2), the default implementation is a no-op.
Engines that *do* support timestamps (e.g., Postgres) should override this function."
(
fn
[
_
]))
(
defn-
value->base-type
"Attempt to match a value we get back from the DB with the corresponding base-type`."
[
v
]
...
...
@@ -48,9 +36,9 @@
;; If timezone is specified in the Query and the driver supports setting the timezone then execute SQL to set it
(
when-let
[
timezone
(
or
(
->
query
:native
:timezone
)
(
->
@
(
:organization
database
)
:report_timezone
))]
(
when-let
[
set-timezone-sql
(
*
timezone->set-timezone-sql
*
timezone
)]
(
when-let
[
timezone->
set-timezone-sql
(
:
timezone->set-timezone-sql
(
driver/database-id->driver
database-id
)
)]
(
log/debug
"Setting timezone to:"
timezone
)
(
jdbc/db-do-prepared
conn
set-timezone-sql
)))
(
jdbc/db-do-prepared
conn
(
timezone->
set-timezone-sql
timezone
)
)))
(
jdbc/query
conn
sql
:as-arrays?
true
))]
{
:rows
rows
:columns
columns
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment