https://github.com/marschall/sqlid
computes the Oracle SQL_ID of a JDBC query string
https://github.com/marschall/sqlid
jdbc oracle
Last synced: 3 months ago
JSON representation
computes the Oracle SQL_ID of a JDBC query string
- Host: GitHub
- URL: https://github.com/marschall/sqlid
- Owner: marschall
- Created: 2021-06-12T10:23:03.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2021-12-10T11:06:56.000Z (over 3 years ago)
- Last Synced: 2025-01-16T02:44:55.563Z (4 months ago)
- Topics: jdbc, oracle
- Language: Java
- Homepage:
- Size: 133 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
SQL_ID [](https://maven-badges.herokuapp.com/maven-central/com.github.marschall/sqlid) [](https://javadoc.io/doc/com.github.marschall/sqlid)
======Computes the Oracle SQL_ID of a JDBC query string.
There are three different sources from which a SQL_ID can be computed:
* From a JDBC query string with positional placeholders for bind variables, eg `"SELECT * FROM dual WHERE dummy = ?"`
* From a native query string with named placeholders for bind variables, eg `"SELECT * FROM dual WHERE dummy = :val"`
* From a `SQLException`Usage
-----```xml
com.github.marschall
sqlid
1.0.0```
If you already have a native query string with :name as placeholders you can simply use
```java
SqlId.compute("SELECT * FROM dual WHERE dummy = :1 ");
```If you have a JDBC query string with ? as placeholders you first need to call `java.sql.Connection#nativeSQL(String)` to convert it to a native query string.
If you want more convenience `SqlIdLookup` takes care of converting form JDBC query strings to native query strings and also performs caching.
```java
SqlIdLookup lookup = new SqlIdLookup(dataSource, 128);
String sqlId = lookup.getSqlIdOfJdbcString("SELECT * FROM dual WHERE dummy = ?");
```SQL_ID algorithm
----------------1. append a `0x00` byte to the native SQL query
1. compute the MD5 hash (it's unclear whether UTF-8 or the database encoding should be used)
1. create a 64 bit long value out last two 32 integer values of the hash using big endian order
1. convert to Base32, 5 bits at a time starting with the most significant bit, using the alphabet `0123456789abcdfghjkmnpqrstuvwxyz`