Skip to content

Commit

Permalink
derelict-pq v2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
denizzzka committed Feb 3, 2016
1 parent 81e5220 commit 5df99f9
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 17 deletions.
2 changes: 1 addition & 1 deletion dub.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
],
"targetPath": "bin",
"dependencies": {
"derelict-pq": "~>1.0.1"
"derelict-pq": "~>2.0.0"
},
"configurations": [
{
Expand Down
26 changes: 13 additions & 13 deletions src/dpq2/answer.d
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ class Answer
package void checkAnswerForErrors() const
{
cast(void) enforceEx!OutOfMemoryError(res, "Can't write query result");
if(!(status == ExecStatusType.PGRES_COMMAND_OK ||
status == ExecStatusType.PGRES_TUPLES_OK))
if(!(status == PGRES_COMMAND_OK ||
status == PGRES_TUPLES_OK))
{
throw new AnswerException( AnswerException.ExceptionTypes.UNDEFINED_FIXME,
resultErrorMessage~" ("~to!string(status)~")" );
Expand Down Expand Up @@ -94,10 +94,10 @@ class Answer
@property size_t columnCount() const { return PQnfields(res); }

/// Returns column format
valueFormat columnFormat( const size_t colNum ) const
ValueFormat columnFormat( const size_t colNum ) const
{
assertCol( colNum );
return PQfformat(res, cast(int)colNum);
return cast(ValueFormat) PQfformat(res, cast(int)colNum);
}

/// Returns column Oid
Expand Down Expand Up @@ -227,9 +227,9 @@ const struct Row
struct Value
{
private ubyte[] value;
private valueFormat format;
private ValueFormat format;

this( const (ubyte)* value, size_t valueSize, valueFormat f )
this( const (ubyte)* value, size_t valueSize, ValueFormat f )
{
this.value = cast(ubyte[]) value[0..valueSize];
format = f;
Expand All @@ -238,14 +238,14 @@ struct Value
this( const ubyte[] value )
{
this.value = cast(ubyte[]) value;
format = valueFormat.BINARY;
format = ValueFormat.BINARY;
}

/// Returns value as bytes from binary formatted field
@property T as(T)() const
if( is( T == const(ubyte[]) ) )
{
enforce( format == valueFormat.BINARY, "Format of the column is not binary" );
enforce( format == ValueFormat.BINARY, "Format of the column is not binary" );
return value;
}

Expand All @@ -262,7 +262,7 @@ struct Value
@property T as(T)() const
if( isNumeric!(T) )
{
enforce( format == valueFormat.BINARY, "Format of the column is not binary" );
enforce( format == ValueFormat.BINARY, "Format of the column is not binary" );
enforce( value.length == T.sizeof, "Value length isn't equal to type size" );

ubyte[T.sizeof] s = value[0..T.sizeof];
Expand Down Expand Up @@ -327,7 +327,7 @@ const struct Array
this(in Value c)
{
cell = c;
enforce( cell.format == valueFormat.BINARY, "Format of the column is not binary" );
enforce( cell.format == ValueFormat.BINARY, "Format of the column is not binary" );

ArrayHeader_net* h = cast(ArrayHeader_net*) cell.value.ptr;
nDims = bigEndianToNative!int(h.ndims);
Expand Down Expand Up @@ -515,8 +515,8 @@ void _integration_test( string connParam )

assert( e.rowCount == 3 );
assert( e.columnCount == 4);
assert( e.columnFormat(1) == valueFormat.TEXT );
assert( e.columnFormat(2) == valueFormat.TEXT );
assert( e.columnFormat(1) == ValueFormat.TEXT );
assert( e.columnFormat(2) == ValueFormat.TEXT );

assert( e[1][2].as!PGtext == "456" );
assert( e[2][1].as!PGtext == "ijk_АБВГД" );
Expand All @@ -527,7 +527,7 @@ void _integration_test( string connParam )

// Value properties test
QueryParams p;
p.resultFormat = valueFormat.BINARY;
p.resultFormat = ValueFormat.BINARY;
p.sqlCommand = "SELECT "~
"-32761::smallint, "~
"-2147483646::integer, "~
Expand Down
2 changes: 1 addition & 1 deletion src/dpq2/connection.d
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class BaseConnection

enforceEx!OutOfMemoryError(conn, "Unable to allocate libpq connection data");

if( !nonBlocking && PQstatus(conn) != ConnStatusType.CONNECTION_OK )
if( !nonBlocking && PQstatus(conn) != CONNECTION_OK )
throw new ConnException();

readyForQuery = true;
Expand Down
8 changes: 6 additions & 2 deletions src/dpq2/query.d
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@ public import dpq2.connection;

import derelict.pq.pq;

enum ValueFormat : ubyte {
TEXT,
BINARY
}

/// Query parameters
struct QueryParams
{
string sqlCommand; /// SQL command
QueryArg[] args; /// SQL command arguments
valueFormat resultFormat = valueFormat.BINARY; /// Result value format
ValueFormat resultFormat = ValueFormat.BINARY; /// Result value format
}

/// Query argument
Expand Down Expand Up @@ -131,7 +135,7 @@ final class Connection: BaseConnection
for( int i = 0; i < p.args.length; ++i )
{
a.types[i] = p.args[i].type;
a.formats[i] = valueFormat.TEXT;
a.formats[i] = ValueFormat.TEXT;
a.values[i] = p.args[i].valueBin.ptr;
a.lengths[i] = p.args[i].valueBin.length;
}
Expand Down

0 comments on commit 5df99f9

Please sign in to comment.