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
fd8f865e
Commit
fd8f865e
authored
9 years ago
by
Cam Saul
Browse files
Options
Downloads
Patches
Plain Diff
rework generic sql native QP to handle expanded DB
parent
e8758fb8
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/metabase/driver/generic_sql/native.clj
+10
-15
10 additions, 15 deletions
src/metabase/driver/generic_sql/native.clj
with
10 additions
and
15 deletions
src/metabase/driver/generic_sql/native.clj
+
10
−
15
View file @
fd8f865e
...
...
@@ -5,10 +5,8 @@
[
clojure.tools.logging
:as
log
]
(
korma
[
core
:as
korma
]
db
)
[
metabase.db
:refer
[
sel
]]
[
metabase.driver
:as
driver
]
[
metabase.driver.generic-sql.util
:refer
:all
]
[
metabase.models.database
:refer
[
Database
]]))
[
metabase.driver.generic-sql.util
:refer
:all
]))
(
defn-
value->base-type
"Attempt to match a value we get back from the DB with the corresponding base-type`."
...
...
@@ -22,30 +20,27 @@
(
defn
process-and-run
"Process and run a native (raw SQL) QUERY."
{
:arglists
'
([
query
])}
[{{
sql
:query
}
:native
database-id
:database
:as
query
}]
{
:pre
[(
string?
sql
)
(
integer?
database-id
)]}
[{{
sql
:query
}
:native,
database
:database,
:as
query
}]
{
:pre
[(
string?
sql
)]}
(
log/debug
"QUERY: \n"
(
with-out-str
(
clojure.pprint/pprint
query
)))
(
try
(
let
[
database
(
sel
:one
Database
:id
database-id
)
db
(
->
database
(
try
(
let
[
db
(
->
database
db->korma-db
korma.db/get-connection
)
[
columns
&
[
first-row
:as
rows
]]
(
jdbc/with-db-transaction
[
conn
db
:read-only?
true
]
;; 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
)
(
driver/report-timezone
))]
(
when-let
[
timezone->set-timezone-sql
(
:timezone->set-timezone-sql
(
driver/
database-id->driver
database
-id
))]
(
when-let
[
timezone->set-timezone-sql
(
:timezone->set-timezone-sql
(
driver/
engine->driver
(
:engine
database
)
))]
(
log/debug
"Setting timezone to:"
timezone
)
(
jdbc/db-do-prepared
conn
(
timezone->set-timezone-sql
timezone
))))
(
jdbc/query
conn
sql
:as-arrays?
true
))]
{
:rows
rows
{
:rows
rows
:columns
columns
:cols
(
map
(
fn
[
column
first-value
]
{
:name
column
:base_type
(
value->base-type
first-value
)})
columns
first-row
)})
:cols
(
map
(
fn
[
column
first-value
]
{
:name
column
:base_type
(
value->base-type
first-value
)})
columns
first-row
)})
(
catch
java.sql.SQLException
e
(
let
[
^
String
message
(
or
(
->>
(
.getMessage
e
)
; error message comes back like 'Column "ZID" not found; SQL statement: ... [error-code]' sometimes
(
re-find
#
"^(.*);"
)
; the user already knows the SQL, and error code is meaningless
...
...
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