Skip to content

Commit

Permalink
feat(odbc): add ODBC bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
Spasi committed Nov 19, 2017
1 parent 8edbd78 commit e4fdebd
Show file tree
Hide file tree
Showing 13 changed files with 4,744 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ improve the chances of a quick and useful response.
|[jemalloc](http://www.canonware.com/jemalloc/)|A general purpose malloc implementation that emphasizes fragmentation avoidance and scalable concurrency support.|
|[LMDB](https://symas.com/products/lightning-memory-mapped-database/)|An extraordinarily fast, memory-efficient database. With memory-mapped files, it has the read performance of a pure in-memory database while retaining the persistence of standard disk-based databases.|
|[LZ4](http://lz4.github.io/lz4/)|A lossless data compression algorithm that is focused on compression and decompression speed.|
|[ODBC](https://docs.microsoft.com/en-us/sql/odbc/microsoft-open-database-connectivity-odbc)|A C programming language interface that makes it possible for applications to access data from a variety of database management systems (DBMSs).|
|[Remotery](https://github.com/Celtoys/Remotery)|A realtime CPU/GPU profiler hosted in a single C file with a viewer that runs in a web browser.|
|[rpmalloc](https://github.com/rampantpixels/rpmalloc)|A public domain cross platform lock free thread caching 16-byte aligned memory allocator implemented in C.|
|[xxHash](https://github.com/Cyan4973/xxHash)|An Extremely fast Hash algorithm, running at RAM speed limits.|
Expand Down
5 changes: 5 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ enum Artifacts {
"A minimal state immediate mode graphical user interface toolkit.",
Platforms.ALL
),
ODBC(
"lwjgl-odbc", "LWJGL - ODBC bindings",
"A C programming language interface that makes it possible for applications to access data from a variety of database management systems (DBMSs).",
Platforms.JAVA_ONLY
),
OPENAL(
"lwjgl-openal", "LWJGL - OpenAL bindings",
"A cross-platform 3D audio API appropriate for use with gaming applications and many other types of audio applications.",
Expand Down
5 changes: 5 additions & 0 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@
<src path="${src.templates.kotlin}/org/lwjgl/hwloc" if:true="${binding.hwloc}"/>
<src path="${src.templates.kotlin}/org/lwjgl/nanovg" if:true="${binding.nanovg}"/>
<src path="${src.templates.kotlin}/org/lwjgl/nuklear" if:true="${binding.nuklear}"/>
<src path="${src.templates.kotlin}/org/lwjgl/odbc" if:true="${binding.odbc}"/>
<src path="${src.templates.kotlin}/org/lwjgl/openal" if:true="${binding.openal}"/>
<src path="${src.templates.kotlin}/org/lwjgl/opencl" if:true="${binding.opencl}"/>
<src path="${src.templates.kotlin}/org/lwjgl/opencl/CLTypes.kt" if:true="${opencl_types}"/>
Expand Down Expand Up @@ -344,6 +345,7 @@
<exclude name="org/lwjgl/assimp/**" unless:true="${binding.assimp}"/>
<exclude name="org/lwjgl/bgfx/**" unless:true="${binding.bgfx}"/>
<exclude name="org/lwjgl/nuklear/**" unless:true="${binding.nuklear}"/>
<exclude name="org/lwjgl/odbc/**" unless:true="${binding.odbc}"/>
<exclude name="org/lwjgl/openvr/**" unless:true="${binding.openvr}"/>
<exclude name="org/lwjgl/ovr/**" unless:true="${binding.ovr}"/>
<exclude name="org/lwjgl/stb/**" unless:true="${binding.stb}"/>
Expand Down Expand Up @@ -1095,6 +1097,9 @@
<!-- Nuklear -->
<release-module package="org.lwjgl.nuklear" name="nuklear" native-library="lwjgl_nuklear" title="Nuklear" if:true="${binding.nuklear}"/>

<!-- ODBC -->
<release-module package="org.lwjgl.odbc" name="odbc" java-only="true" title="ODBC" if:true="${binding.odbc}"/>

<!-- OpenAL -->
<release-module package="org.lwjgl.openal" name="openal" title="OpenAL" license="openal" if:true="${binding.openal}">
<natives>
Expand Down
4 changes: 3 additions & 1 deletion config/build-bindings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ This script is included in /config/build-definitions.xml.
<property name="binding.nanovg" value="true"/>
<property name="binding.nfd" value="true"/>
<property name="binding.nuklear" value="true"/>
<property name="binding.odbc" value="true"/>
<property name="binding.openal" value="true"/>
<property name="binding.opencl" value="true"/>
<property name="binding.opengl" value="true"/>
Expand All @@ -43,7 +44,8 @@ This script is included in /config/build-definitions.xml.
<property name="binding.zstd" value="true"/>

<!-- Set the path to the Oculus SDK to enable. -->
<property name="OCULUS_SDK_PATH" location="../OculusSDK" relative="false"/>
<!-- TODO: add headers in here -->
<property name="OCULUS_SDK_PATH" location="../../CLONES/OculusSDK" relative="false"/>

<!-- // ================================ // -->

Expand Down
1 change: 1 addition & 0 deletions doc/notes/3.1.4.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ This build includes the following changes:

- Added [LZ4](http://lz4.github.io/lz4/) bindings.
- Added [NanoSVG](https://github.com/memononen/nanosvg) to the existing `NanoVG` bindings.
- Added [ODBC](https://docs.microsoft.com/en-us/sql/odbc/microsoft-open-database-connectivity-odbc) bindings.
- Added [Remotery](https://github.com/Celtoys/Remotery) bindings.
- Added [Zstandard](http://facebook.github.io/zstd/) bindings.
- bgfx: Updated to API version 55 (up from 48)
Expand Down
2 changes: 2 additions & 0 deletions modules/core/src/main/java/org/lwjgl/system/Checks.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ private Checks() {
public static int lengthSafe(short[] array) { return array == null ? 0 : array.length;}
public static int lengthSafe(int[] array) { return array == null ? 0 : array.length;}
public static int lengthSafe(long[] array) { return array == null ? 0 : array.length; }
public static int lengthSafe(float[] array) { return array == null ? 0 : array.length;}
public static int lengthSafe(double[] array) { return array == null ? 0 : array.length;}
public static int remainingSafe(Buffer buffer) { return buffer == null ? 0 : buffer.remaining(); }
public static int remainingSafe(CustomBuffer<?> buffer) { return buffer == null ? 0 : buffer.remaining(); }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,11 @@ public class Configuration<T> {
/** Similar to {@link #LIBRARY_NAME} for the jemalloc library (<b>org.lwjgl.system.jemalloc.libname</b>). */
public static final Configuration<String> JEMALLOC_LIBRARY_NAME = new Configuration<>("org.lwjgl.system.jemalloc.libname", StateInit.STRING);

// -- ODBC

/** Similar to {@link #LIBRARY_NAME} for the ODBC library (<b>org.lwjgl.odbc.libname</b>). */
public static final Configuration<String> ODBC_LIBRARY_NAME = new Configuration<>("org.lwjgl.odbc.libname", StateInit.STRING);

// -- OPENAL

/** Similar to {@link #EGL_EXPLICIT_INIT} for the OpenAL library (<b>org.lwjgl.openal.explicitInit</b>). */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ enum class Binding(
NANOVG("binding.nanovg", "org.lwjgl.nanovg"),
NFD("binding.nfd", "org.lwjgl.util.nfd"),
NUKLEAR("binding.nuklear", "org.lwjgl.nuklear"),
ODBC("binding.odbc", "org.lwjgl.odbc"),
OPENAL("binding.openal", "org.lwjgl.openal"),
OPENCL("binding.opencl", "org.lwjgl.opencl"),
OPENGL("binding.opengl", "org.lwjgl.opengl"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* Copyright LWJGL. All rights reserved.
* License terms: https://www.lwjgl.org/license
*/
module org.lwjgl.odbc {
requires transitive org.lwjgl;

exports org.lwjgl.odbc;
}
205 changes: 205 additions & 0 deletions modules/templates/src/main/kotlin/org/lwjgl/odbc/ODBCTypes.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
/*
* Copyright LWJGL. All rights reserved.
* License terms: http://lwjgl.org/license.php
*/
package org.lwjgl.odbc

import org.lwjgl.generator.*
import org.lwjgl.system.windows.*

val ODBC_PACKAGE = "org.lwjgl.odbc"

val ODBC_BINDING = simpleBinding("odbc", "Configuration.ODBC_LIBRARY_NAME, \"odbc32\", \"odbc\"", callingConvention = CallingConvention.STDCALL)
val ODBC_BINDING_DELEGATE = ODBC_BINDING.delegate("SQL.getLibrary()")

fun config() {
packageInfo(
ODBC_PACKAGE,
"""
Contains bindings to ${url("https://docs.microsoft.com/en-us/sql/odbc/microsoft-open-database-connectivity-odbc", "ODBC")}.
The Microsoft Open Database Connectivity (ODBC) interface is a C programming language interface that makes it possible for applications to access data
from a variety of database management systems (DBMSs). ODBC is a low-level, high-performance interface that is designed specifically for relational
data stores.
The ODBC interface allows maximum interoperability — an application can access data in diverse DBMSs through a single interface. Moreover, that
application will be independent of any DBMS from which it accesses data. Users of the application can add software components called drivers, which
interface between an application and a specific DBMS.
"""
)
}

val SQLCHAR = typedef(unsigned_char, "SQLCHAR")
val SQLSCHAR = IntegerType("SQLSCHAR", PrimitiveMapping.BYTE, unsigned = true)
val SQLWCHAR = typedef(unsigned_short, "SQLWCHAR")

val SQLTCHAR = typedef(SQLWCHAR, "SQLTCHAR")

val SQLCHARASCII_p = CharSequenceType(name = "SQLCHAR", charMapping = CharMapping.ASCII)
val SQLCHARUTF16_p = CharSequenceType(name = "SQLWCHAR", charMapping = CharMapping.UTF16)

val SQLSMALLINT = typedef(short, "SQLSMALLINT")
val SQLSMALLINT_p = SQLSMALLINT.p
val SQLUSMALLINT = typedef(unsigned_short, "SQLUSMALLINT")
val SQLUSMALLINT_p = SQLUSMALLINT.p

val long = IntegerType("long", PrimitiveMapping.INT)
val unsigned_long = IntegerType("unsigned long", PrimitiveMapping.INT, unsigned = true)

val SQLINTEGER = typedef(long, "SQLINTEGER")
val SQLINTEGER_p = SQLINTEGER.p
val SQLUINTEGER = typedef(unsigned_long, "SQLUINTEGER")

val SQLRETURN = typedef(SQLSMALLINT, "SQLRETURN")

val SQLPOINTER = typedef(void_p, "SQLPOINTER")
val SQLPOINTER_p = SQLPOINTER.p

val SQLLEN = IntegerType("SQLLEN", PrimitiveMapping.POINTER)
val SQLLEN_p = SQLLEN.p
val SQLULEN = IntegerType("SQLULEN", PrimitiveMapping.POINTER, unsigned = true)
val SQLULEN_p = SQLULEN.p

val SQLSETPOSIROW = IntegerType("SQLSETPOSIROW", PrimitiveMapping.LONG, unsigned = true)

val SQLHANDLE = PointerType("SQLHANDLE", includesPointer = true)
val SQLHANDLE_p = SQLHANDLE.p

val SQLHENV = typedef(SQLHANDLE, "SQLHENV")
val SQLHDBC = typedef(SQLHANDLE, "SQLHDBC")
val SQLHSTMT = typedef(SQLHANDLE, "SQLHSTMT")
val SQLHDESC = typedef(SQLHANDLE, "SQLHDESC")
val SQLHWND = typedef(HWND, "SQLHWND")

val RETCODE = IntegerType("RETCODE", PrimitiveMapping.SHORT)
val RETCODE_p = RETCODE.p

// sqltypes.h structs

val SQL_DATE_STRUCT = struct(ODBC_PACKAGE, "SQL_DATE_STRUCT") {
SQLSMALLINT.member("year", "")
SQLUSMALLINT.member("month", "")
SQLUSMALLINT.member("day", "")
}

val SQL_TIME_STRUCT = struct(ODBC_PACKAGE, "SQL_TIME_STRUCT") {
SQLUSMALLINT.member("hour", "")
SQLUSMALLINT.member("minute", "")
SQLUSMALLINT.member("second", "")
}

val SQL_TIMESTAMP_STRUCT = struct(ODBC_PACKAGE, "SQL_TIMESTAMP_STRUCT") {
SQLSMALLINT.member("year", "")
SQLUSMALLINT.member("month", "")
SQLUSMALLINT.member("day", "")
SQLUSMALLINT.member("hour", "")
SQLUSMALLINT.member("minute", "")
SQLUSMALLINT.member("second", "")
SQLUINTEGER.member("fraction", "")
}

val SQL_YEAR_MONTH_STRUCT = struct(ODBC_PACKAGE, "SQL_YEAR_MONTH_STRUCT") {
SQLUINTEGER.member("year", "")
SQLUINTEGER.member("month", "")
}

val SQL_DAY_SECOND_STRUCT = struct(ODBC_PACKAGE, "SQL_DAY_SECOND_STRUCT") {
SQLUINTEGER.member("day", "")
SQLUINTEGER.member("hour", "")
SQLUINTEGER.member("minute", "")
SQLUINTEGER.member("second", "")
SQLUINTEGER.member("fraction", "")
}

val SQLINTERVAL = typedef(int, "SQLINTERVAL")
val SQL_INTERVAL_STRUCT = struct(ODBC_PACKAGE, "SQL_INTERVAL_STRUCT") {
SQLINTERVAL.member("interval_type", "")
SQLSMALLINT.member("interval_sign", "")
struct("intval", "") {
SQL_YEAR_MONTH_STRUCT.member("year_month", "")
SQL_DAY_SECOND_STRUCT.member("day_second", "")
}
}

val SQL_NUMERIC_STRUCT = struct(ODBC_PACKAGE, "SQL_NUMERIC_STRUCT") {
SQLCHAR.member("precision", "")
SQLSCHAR.member("scale", "")
SQLCHAR.member("sign", "")
SQLCHAR.array("val", "", size = 16 /*SQL_MAX_NUMERIC_LEN*/)
}

// sqlncli.h structs

val DBMONEY = struct(ODBC_PACKAGE, "DBMONEY") {
LONG.member("mnyhigh", "")
ULONG.member("mnylow", "")
}

val DBDATETIME = struct(ODBC_PACKAGE, "DBDATETIME") {
LONG.member("dtdays", "")
ULONG.member("dttime", "")
}

val DBDATETIM4 = struct(ODBC_PACKAGE, "DBDATETIM4") {
USHORT.member("numdays", "")
USHORT.member("nummins", "")
}

val SQL_SS_TIME2_STRUCT = struct(ODBC_PACKAGE, "SQL_SS_TIME2_STRUCT") {
SQLUSMALLINT.member("hour", "")
SQLUSMALLINT.member("minute", "")
SQLUSMALLINT.member("second", "")
SQLUINTEGER.member("fraction", "")
}

val SQL_SS_TIMESTAMPOFFSET_STRUCT = struct(ODBC_PACKAGE, "SQL_SS_TIMESTAMPOFFSET_STRUCT") {
SQLSMALLINT.member("year", "")
SQLUSMALLINT.member("month", "")
SQLUSMALLINT.member("day", "")
SQLUSMALLINT.member("hour", "")
SQLUSMALLINT.member("minute", "")
SQLUSMALLINT.member("second", "")
SQLUINTEGER.member("fraction", "")
SQLSMALLINT.member("timezone_hour", "")
SQLSMALLINT.member("timezone_minute", "")
}

val SQLPERF = struct(ODBC_PACKAGE, "SQLPERF") {
// Application Profile Statistics
DWORD.member("TimerResolution", "")
DWORD.member("SQLidu", "")
DWORD.member("SQLiduRows", "")
DWORD.member("SQLSelects", "")
DWORD.member("SQLSelectRows", "")
DWORD.member("Transactions", "")
DWORD.member("SQLPrepares", "")
DWORD.member("ExecDirects", "")
DWORD.member("SQLExecutes", "")
DWORD.member("CursorOpens", "")
DWORD.member("CursorSize", "")
DWORD.member("CursorUsed", "")
LDOUBLE.member("PercentCursorUsed", "")
LDOUBLE.member("AvgFetchTime", "")
LDOUBLE.member("AvgCursorSize", "")
LDOUBLE.member("AvgCursorUsed", "")
DWORD.member("SQLFetchTime", "")
DWORD.member("SQLFetchCount", "")
DWORD.member("CurrentStmtCount", "")
DWORD.member("MaxOpenStmt", "")
DWORD.member("SumOpenStmt", "")
// Connection Statistics
DWORD.member("CurrentConnectionCount", "")
DWORD.member("MaxConnectionsOpened", "")
DWORD.member("SumConnectionsOpened", "")
DWORD.member("SumConnectiontime", "")
LDOUBLE.member("AvgTimeOpened", "")
// Network Statistics
DWORD.member("ServerRndTrips", "")
DWORD.member("BuffersSent", "")
DWORD.member("BuffersRec", "")
DWORD.member("BytesSent", "")
DWORD.member("BytesRec", "")
// Time Statistics
DWORD.member("msExecutionTime", "")
DWORD.member("msNetWorkServerTime", "")
}
Loading

0 comments on commit e4fdebd

Please sign in to comment.