Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: evosec/metabase-firebird-driver
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.3.0
Choose a base ref
...
head repository: evosec/metabase-firebird-driver
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: develop
Choose a head ref
  • 18 commits
  • 6 files changed
  • 4 contributors

Commits on Mar 2, 2021

  1. Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    Nikos410 Nikos Epping
    Copy the full SHA
    fd95728 View commit details

Commits on Mar 3, 2021

  1. Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    Nikos410 Nikos Epping
    Copy the full SHA
    e3bb450 View commit details

Commits on Mar 4, 2021

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    262bfd9 View commit details

Commits on Mar 30, 2021

  1. 1

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    6550955 View commit details

Commits on Jul 19, 2021

  1. Copy the full SHA
    5d7a216 View commit details
  2. Update to support Metabase 0.40+

    mat02 committed Jul 19, 2021
    Copy the full SHA
    90e797b View commit details
  3. Fix for FB2.x - SUBSTRING function

    mat02 committed Jul 19, 2021
    Copy the full SHA
    512ea07 View commit details
  4. Copy the full SHA
    33734ce View commit details

Commits on Jul 29, 2021

  1. Merge pull request #15 from mat02/develop

    Fix compatibility with FB2.x
    Nikos410 authored Jul 29, 2021

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    2e55040 View commit details
  2. Release v1.4.0

    Nikos410 committed Jul 29, 2021
    Copy the full SHA
    c313da6 View commit details

Commits on Aug 9, 2022

  1. Update README.md

    Nikos410 authored Aug 9, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    95602eb View commit details

Commits on Jul 18, 2023

  1. Add deps and build script

    Nikos410 committed Jul 18, 2023
    Copy the full SHA
    6b63012 View commit details
  2. Copy the full SHA
    fd269f3 View commit details
  3. Merge pull request #18 from camsaul/patch-1

    Fix overriding global method for all `:sql-jdbc` drivers
    Nikos410 authored Jul 18, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    1cc14a8 View commit details
  4. Update README.md

    Nikos410 authored Jul 18, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    3088817 View commit details
  5. Remove project.clj

    Nikos410 committed Jul 18, 2023
    Copy the full SHA
    2476407 View commit details
  6. Copy the full SHA
    1490965 View commit details
  7. Release v1.5.0

    Nikos410 committed Jul 18, 2023
    10
    Copy the full SHA
    6314b3c View commit details
Showing with 110 additions and 38 deletions.
  1. +1 −1 LICENSE
  2. +22 −17 README.md
  3. +14 −0 build.sh
  4. +16 −0 deps.edn
  5. +0 −16 project.clj
  6. +57 −4 src/metabase/driver/firebird.clj
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2018 - 2019 Evosec GmbH & Co. KG
Copyright (c) 2018 - 2021 Evosec GmbH & Co. KG

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
39 changes: 22 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,40 @@
:warning: This plugin needs the new modular driver system to work, which is available since Metabase version 0.32.

# Firebird driver for metabase

This driver enables metabase to connect to [FirebirdSQL](https://firebirdsql.org/) databases.

## Installation:

* Make sure you have installed a recent Metabase Version that supports drivers as plugins. (>=0.32)
* Download the [latest release](https://github.com/evosec/metabase-firebird-driver/releases/latest) of the Firebird driver or build it from source. (See below)
* Make sure you have installed a recent Metabase Version.
* Download the [latest release](https://github.com/evosec/metabase-firebird-driver/releases/latest) of the Firebird driver or [build it from source](#building-from-source).
* Create the `plugins` directory if it doesn't already exist. By default that directory is next to the metabase.jar file, but you can specify a different directory by setting the environment varianble `MB_PLUGINS_DIR`.
* Just drop the `firebird.metabase-driver.jar` in the plugins directory. On startup, metabase will load the plugin and the driver should be available.

## Building from source:
## Authentication issues when using Legacy_Auth

For a detailed description, take a look at the [official documentation](https://github.com/metabase/metabase/wiki/Writing-A-Driver).
The latest releases are built with version 4.x of Jaybird (the Firebird JDBC driver), [which no longer supports Legacy_Auth](https://www.firebirdsql.org/file/documentation/drivers_documentation/java/4.0.0/release_notes.html#removed-legacy_auth-from-default-authentication-plugins).

#### Prepare a local Metabase installation for building drivers
:warning: First of all: Legacy_Auth is disabled for a reason. You should only use the following workarounds if you have no way of using a more secure authentication method. :warning:

* Download the Metabase sources (>=0.32)
* Compile a local Metabase installation for building drivers
If you really need to access your database using Legacy_Auth ([#14](https://github.com/evosec/metabase-firebird-driver/issues/14)) you can [add it to the authentication plugins](https://www.firebirdsql.org/file/documentation/drivers_documentation/java/4.0.0/release_notes.html#configure-authentication-plugins). For example:
```
cd /path/to/metabase/source
lein install-for-building-drivers
jdbc:firebirdsql://localhost/employee?authPlugins=Legacy_Auth
```

#### Build the driver
If that does not work for you, you can use the release artifact `firebird.metabase-driver_jaybird-3.jar` which is built with Jaybird 3.x.

## Building from source:

* Download the Firebird driver sources
* Build the driver. This will create the .jar file in the directory `target/uberjar`. Just copy that file to your plugins directory and you are good to go!
For a detailed description, take a look at the [official documentation](https://www.metabase.com/docs/latest/developers-guide/drivers/start.html).

* Checkout the main metabase repository and the firebird driver repository in the same parent directory:
```
workspace
- metabase
- metabase-firebird-driver
```
* Run the `build.sh` script from the metabase-firebird-driver repository
```
cd /path/to/firebird-driver
lein clean
LEIN_SNAPSHOTS_IN_RELEASE=true DEBUG=1 lein uberjar
cd metabase-firebird-driver
./build.sh
```
* The driver will now be built. The .jar file can be found in the `target` directory.
14 changes: 14 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Example for building the driver with bash or similar

DRIVER_PATH=`pwd`

# switch to the local checkout of the Metabase repo
cd ../metabase

# get absolute path to the driver project directory

clojure \
-Sdeps "{:aliases {:firebird {:extra-deps {evosec/firebird-driver {:local/root \"$DRIVER_PATH\"}}}}}" \
-X:build:firebird \
build-drivers.build-driver/build-driver! \
"{:driver :firebird, :project-dir \"$DRIVER_PATH\", :target-dir \"$DRIVER_PATH/target\"}"
16 changes: 16 additions & 0 deletions deps.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{:paths
["src" "resources"]


:deps
{org.firebirdsql.jdbc/jaybird {:mvn/version "4.0.9.java8"}}

;; build the driver with clojure -X:build
:aliases
{:build
{:extra-deps {metabase/metabase-core {:local/root "../metabase"}
metabase/build-drivers {:local/root "../metabase/bin/build-drivers"}}
:exec-fn build-drivers.build-driver/build-driver!
:exec-args {:driver :firebird
:project-dir "."
:target-dir "./target"}}}}
16 changes: 0 additions & 16 deletions project.clj

This file was deleted.

61 changes: 57 additions & 4 deletions src/metabase/driver/firebird.clj
Original file line number Diff line number Diff line change
@@ -4,19 +4,24 @@
[string :as str]]
[clojure.java.jdbc :as jdbc]
[honeysql.core :as hsql]
[honeysql.format :as hformat]
[java-time :as t]
[metabase.driver :as driver]
[metabase.driver.common :as driver.common]
;; [metabase.driver.sql-jdbc.sync.describe-database :as sql-jdbc.sync.describe-database]
[metabase.driver.sql-jdbc
[common :as sql-jdbc.common]
[connection :as sql-jdbc.conn]
[sync :as sql-jdbc.sync]]
[metabase.driver.sql-jdbc.sync.common :as sql-jdbc.sync.common]
[metabase.driver.sql.query-processor :as sql.qp]
[metabase.util
[honeysql-extensions :as hx]
[ssh :as ssh]])
[honeysql-extensions :as hx]]
[metabase.util.ssh :as ssh])
(:import [java.sql DatabaseMetaData Time]
[java.time LocalDate LocalDateTime LocalTime OffsetDateTime OffsetTime ZonedDateTime]))
[java.time LocalDate LocalDateTime LocalTime OffsetDateTime OffsetTime ZonedDateTime]
[java.sql Connection DatabaseMetaData ResultSet]))


(driver/register! :firebird, :parent :sql-jdbc)

@@ -42,7 +47,7 @@
(sql-jdbc.common/handle-additional-options details)))

(defmethod driver/can-connect? :firebird [driver details]
(let [connection (sql-jdbc.conn/connection-details->spec driver (ssh/include-ssh-tunnel details))]
(let [connection (sql-jdbc.conn/connection-details->spec driver (ssh/include-ssh-tunnel! details))]
(= 1 (first (vals (first (jdbc/query connection ["SELECT 1 FROM RDB$DATABASE"])))))))

;; Use pattern matching because some parameters can have a length parameter, e.g. VARCHAR(255)
@@ -80,6 +85,37 @@
items
(* items (dec page)))]))


;; When selecting constants Firebird doesn't check privileges, we have to select all fields
(defn simple-select-probe-query
[driver schema table]
{:pre [(string? table)]}
(let [honeysql {:select [:*]
:from [(sql.qp/->honeysql driver (hx/identifier :table schema table))]
:where [:not= 1 1]}
honeysql (sql.qp/apply-top-level-clause driver :limit honeysql {:limit 0})]
(sql.qp/format-honeysql driver honeysql)))

(defn- execute-select-probe-query
[driver ^Connection conn [sql & params]]
{:pre [(string? sql)]}
(with-open [stmt (sql-jdbc.sync.common/prepare-statement driver conn sql params)]
;; attempting to execute the SQL statement will throw an Exception if we don't have permissions; otherwise it will
;; truthy wheter or not it returns a ResultSet, but we can ignore that since we have enough info to proceed at
;; this point.
(.execute stmt)))

(defmethod sql-jdbc.sync/have-select-privilege? :firebird
[driver conn table-schema table-name]
;; Query completes = we have SELECT privileges
;; Query throws some sort of no permissions exception = no SELECT privileges
(let [sql-args (simple-select-probe-query driver table-schema table-name)]
(try
(execute-select-probe-query driver conn sql-args)
true
(catch Throwable _
false))))

(defmethod sql-jdbc.sync/active-tables :firebird [& args]
(apply sql-jdbc.sync/post-filtered-active-tables args))

@@ -153,6 +189,23 @@
(defmethod sql.qp/date [:firebird :quarter-of-year] [_ _ expr] (hx/+ (hx// (hx/- (hsql/call :extract :MONTH expr) 1) 3) 1))
(defmethod sql.qp/date [:firebird :year] [_ _ expr] (hsql/call :extract :YEAR expr))

;; Firebird 2.x doesn't support TRUE/FALSE, replacing them with 1 and 0
(defmethod sql.qp/->honeysql [:firebird Boolean] [_ bool] (if bool 1 0))

;; Firebird 2.x doesn't support SUBSTRING arugments seperated by commas, but uses FROM and FOR keywords
(defmethod sql.qp/->honeysql [:firebird :substring]
[driver [_ arg start length]]
(let [col-name (hformat/to-sql (sql.qp/->honeysql driver arg))]
(if length
(reify
hformat/ToSql
(to-sql [_]
(str "substring(" col-name " FROM " start " FOR " length ")")))
(reify
hformat/ToSql
(to-sql [_]
(str "substring(" col-name " FROM " start ")"))))))

(defmethod sql.qp/add-interval-honeysql-form :firebird [driver hsql-form amount unit]
(if (= unit :quarter)
(recur driver hsql-form (hx/* amount 3) :month)