Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for JSON data type #2

Open
wants to merge 58 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
0db879c
Merge pull request #21 from simendsjo/master
sshamov Sep 22, 2013
fd11ec4
Add opDollar to ResultSet.
Oct 6, 2013
b1bacb6
Add license field.
s-ludwig Oct 17, 2013
4b91768
Add vibe.d as an optional dependency so that Have_vibe_d gets defined…
s-ludwig Nov 14, 2013
6164f9a
Fix compiler error for the latest vibe.d master. Fixes #25.
s-ludwig Nov 26, 2013
5d4ebc1
Remove checking _valid (which no longer exists) from execFunction and…
schancel Nov 30, 2013
e0b354e
Merge pull request #26 from schancel/fix_valid
sshamov Nov 30, 2013
31d93e7
Added a few missing casts.
Dec 5, 2013
9e64eaf
Merge remote-tracking branch 'upstream/master'
Dec 5, 2013
37d3d9f
Merge pull request #27 from ArjanKn/master
sshamov Dec 5, 2013
c7af225
Add .gitignore
Geod24 Feb 18, 2014
f7b8a2b
Merge pull request #32 from Geod24/add-gitignore
s-ludwig Feb 18, 2014
496523f
Error message was not displayed, because IFTI doesn't work with classes.
Geod24 Feb 16, 2014
7385698
Merge pull request #31 from Geod24/mysql-error-message
s-ludwig Feb 19, 2014
3007e59
Fix #30: Thrown exceptions leave connections in an undefined state.
Apr 8, 2014
ea30b6c
Avoid using deprecated vibe.d symbols.
s-ludwig Apr 21, 2014
e1e4bfb
add colNames and colNameIndicies to ResultSequence
Apr 24, 2014
39bcaf8
detect nullable types and call nullify in toStruct
Apr 24, 2014
e02b6af
Merge pull request #36 from MartinNowak/columnNames
Abscissa Apr 24, 2014
838c71f
Merge pull request #37 from MartinNowak/nullify
Abscissa Apr 24, 2014
601cca6
fix empty for ResultSequence
MartinNowak Apr 30, 2014
2e97d24
Merge pull request #38 from MartinNowak/SequenceEmpty
Abscissa Apr 30, 2014
1dd2996
Fix #40: Hangs when receiving a value > 250 bytes.
May 30, 2014
162700a
Remove dead-code function parseLCB.
May 30, 2014
aa4acfd
Fix #29: Misleading error message when trying to access results via a…
May 30, 2014
84126e6
docs: A few function names were out of date.
May 30, 2014
4b8fc85
Tightened word wrapping in docs. (We don't have to stick to 80 cols, …
May 30, 2014
d5ed6c1
Fixed MetaData.columns.
Jun 6, 2014
8bd6555
Enable test suite (resurrected old disabled tests, and merged in test…
Jun 6, 2014
226dbe6
Resurrect another unittest.
Jun 6, 2014
69a8785
Resurrect LCB/LCS tests.
Jun 6, 2014
0218503
Regression test for Issue #40 (likely also #18).
Jun 6, 2014
455a95e
Split into multiple modules.
Jun 13, 2014
f599f5d
Fix #45: Retrieving table metadata fails with an exception for certai…
Aug 13, 2014
a93d9ec
tabs->spaces
Aug 13, 2014
6bc8c23
When querying for a table's column metadata, limit search to the appr…
Aug 13, 2014
924b0db
Remove redundant (and outdated) "homepage" field from package.json.
s-ludwig Oct 2, 2014
b233dab
Fix #48: Unittests dont work on MariaDB 5.5
Oct 3, 2014
4199dca
Fixed #39: Unsupported SQL type NEWDECIMAL
Oct 3, 2014
31b178f
tabs -> spaces
Oct 3, 2014
e516fed
Accidentally lost a comment in a previous commit
Oct 3, 2014
8211fe4
Merge branch 'master' of github.com:mysql-d/mysql-native
Oct 3, 2014
3b60eaa
Fix #42: Cant login with empty password
Oct 4, 2014
b16a464
Protocol treats BIT as a LCB (length coded binary), not as an integra…
Oct 5, 2014
557fb01
Fixed: Test don't compile on DMD 2.064.2
Oct 5, 2014
84ad287
Fix a couple DDoc warnings.
Oct 5, 2014
2007dce
TEXT types should be string, not ubyte[] (Fixes #33)
Oct 5, 2014
2815be7
Fixed: Wrong number of bytes read
sshamov Jan 24, 2015
ae79e32
Replace string with const(char)[] for sql string
mathias-baumann-sociomantic Feb 2, 2015
711d27e
Merge pull request #55 from mathias-baumann-sociomantic/conststr
Abscissa Feb 2, 2015
e9283a5
Fix #56: Result set quantity does not equal MySQL rows quantity
Mar 31, 2015
e742bf0
Add 'execSQL' overload for when you don't care about "rows affected".…
Abscissa Aug 8, 2015
28b2b70
Add escape functions
Marenz Oct 23, 2015
26e18e1
Merge pull request #61 from Marenz/escape
Abscissa Oct 23, 2015
4907eb7
Documentation typo
brad-anderson Oct 29, 2015
4cdd088
Merge pull request #62 from eco/patch-1
Abscissa Oct 29, 2015
617c54c
MySQL now directly supports JSON
Csmith1991 Nov 30, 2015
8e1f473
Return Json value for Vibe
Csmith1991 Nov 30, 2015
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
*.[oa]
*.so
*.lib
*.dll
*.exe
.dub

# Executable file name when 'dub' is run on linux
mysql-native
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "mysql-native",
"description": "A native MySQL driver implementation based on Steve Teale's original",
"homepage": "https://github.com/rejectedsoftware/mysql-native",
"license": "BSL-1.0",
"copyright": "Copyright (c) 2011 Steve Teale",
"authors": [
"Steve Teale",
Expand All @@ -11,6 +11,9 @@
"sshamov",
"Nick Sabalausky"
],
"dependencies": {
"vibe-d": {"version": ">=0.7.17", "optional": true}
},
"configurations": [
{
"name": "application",
Expand All @@ -22,4 +25,4 @@
"excludedSourceFiles": ["source/app.d"]
}
]
}
}
185 changes: 185 additions & 0 deletions source/mysql/common.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
module mysql.common;

import std.algorithm;
import std.conv;
import std.datetime;
import std.digest.sha;
import std.exception;
import std.range;
import std.socket;
import std.stdio;
import std.string;
import std.traits;
import std.variant;

version(Have_vibe_d)
{
static if(__traits(compiles, (){ import vibe.core.net; } ))
import vibe.core.net;
else
static assert(false, "mysql-native can't find Vibe.d's 'vibe.core.net'.");
}

/**
* An exception type to distinguish exceptions thrown by this module.
*/
class MySQLException: Exception
{
this(string msg, string file = __FILE__, size_t line = __LINE__) pure
{
super(msg, file, line);
}
}
alias MySQLException MYX;

/**
* Received invalid data from the server which violates the MySQL network protocol.
*/
class MySQLProtocolException: MySQLException
{
this(string msg, string file, size_t line) pure
{
super(msg, file, line);
}
}
alias MySQLProtocolException MYXProtocol;

// Phobos/Vibe.d type aliases
package alias std.socket.TcpSocket PlainPhobosSocket;
version(Have_vibe_d)
{
package alias vibe.core.net.TCPConnection PlainVibeDSocket;
}
else
{
// Dummy types
package alias Object PlainVibeDSocket;
}

alias PlainPhobosSocket function(string,ushort) OpenSocketCallbackPhobos;
alias PlainVibeDSocket function(string,ushort) OpenSocketCallbackVibeD;

enum MySQLSocketType { phobos, vibed }

// A minimal socket interface similar to Vibe.d's TCPConnection.
// Used to wrap both Phobos and Vibe.d sockets with a common interface.
package interface MySQLSocket
{
void close();
@property bool connected() const;
void read(ubyte[] dst);
void write(in ubyte[] bytes);

void acquire();
void release();
bool isOwner();
bool amOwner();
}

// Wraps a Phobos socket with the common interface
package class MySQLSocketPhobos : MySQLSocket
{
private PlainPhobosSocket socket;

// The socket should already be open
this(PlainPhobosSocket socket)
{
enforceEx!MYX(socket, "Tried to use a null Phobos socket - Maybe the 'openSocket' callback returned null?");
enforceEx!MYX(socket.isAlive, "Tried to use a closed Phobos socket - Maybe the 'openSocket' callback created a socket but forgot to open it?");
this.socket = socket;
}

invariant()
{
assert(!!socket);
}

void close()
{
socket.shutdown(SocketShutdown.BOTH);
socket.close();
}

@property bool connected() const
{
return socket.isAlive;
}

void read(ubyte[] dst)
{
// Note: I'm a little uncomfortable with this line as it doesn't
// (and can't) update Connection._open. Not sure what can be done,
// but perhaps Connection._open should be eliminated in favor of
// querying the socket's opened/closed state directly.
scope(failure) socket.close();

for (size_t off, len; off < dst.length; off += len) {
len = socket.receive(dst[off..$]);
enforceEx!MYX(len != 0, "Server closed the connection");
enforceEx!MYX(len != socket.ERROR, "Received std.socket.Socket.ERROR");
}
}

void write(in ubyte[] bytes)
{
socket.send(bytes);
}

void acquire() { /+ Do nothing +/ }
void release() { /+ Do nothing +/ }
bool isOwner() { return true; }
bool amOwner() { return true; }
}

// Wraps a Vibe.d socket with the common interface
version(Have_vibe_d) {
package class MySQLSocketVibeD : MySQLSocket
{
private PlainVibeDSocket socket;

// The socket should already be open
this(PlainVibeDSocket socket)
{
enforceEx!MYX(socket, "Tried to use a null Vibe.d socket - Maybe the 'openSocket' callback returned null?");
enforceEx!MYX(socket.connected, "Tried to use a closed Vibe.d socket - Maybe the 'openSocket' callback created a socket but forgot to open it?");
this.socket = socket;
}

invariant()
{
assert(!!socket);
}

void close()
{
socket.close();
}

@property bool connected() const
{
return socket.connected;
}

void read(ubyte[] dst)
{
socket.read(dst);
}

void write(in ubyte[] bytes)
{
socket.write(bytes);
}

static if (is(typeof(&TCPConnection.isOwner))) {
void acquire() { socket.acquire(); }
void release() { socket.release(); }
bool isOwner() { return socket.isOwner(); }
bool amOwner() { return socket.isOwner(); }
} else {
void acquire() { /+ Do nothing +/ }
void release() { /+ Do nothing +/ }
bool isOwner() { return true; }
bool amOwner() { return true; }
}
}
}
Loading