Skip to content
This repository has been archived by the owner on Jun 10, 2024. It is now read-only.

Commit

Permalink
Merge branch 'master' of github.com:oracle-dart/oracle.dart
Browse files Browse the repository at this point in the history
  • Loading branch information
loveridge committed Aug 23, 2015
2 parents 5d64d05 + 03bcbca commit c72c202
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 53 deletions.
32 changes: 0 additions & 32 deletions lib/src/helpers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -184,38 +184,6 @@ oracle::occi::Date NewOracleDateFromDateTime(Dart_Handle dateTime) {
return date;
}

Dart_Handle NewByteDataFromOracleBytes(oracle::occi::Bytes bytes) {
if (bytes.isNull()) {
return Dart_Null();
}

Dart_Handle byteData = HandleError(Dart_NewTypedData(Dart_TypedData_kByteData,
bytes.length()));

for (int i = 0; i < bytes.length(); i++) {
Dart_Handle b = HandleError(Dart_NewInteger(bytes.byteAt(i)));

HandleError(Dart_Invoke(byteData,
Dart_NewStringFromCString("setUint8"),
1,
&b));
}

return byteData;
}

oracle::occi::Bytes NewOracleBytesFromByteData(Dart_Handle byteData) {

}


void printDartToString(Dart_Handle dh) {
char *tostr;
Dart_StringToCString(Dart_ToString(dh), (const char **)&tostr);

printf("%s\n", tostr);
}

Dart_Handle HandleError(Dart_Handle handle) {
if (Dart_IsError(handle)) Dart_PropagateError(handle);
return handle;
Expand Down
2 changes: 0 additions & 2 deletions lib/src/occi_extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,6 @@ class Statement {
setInt(index, input);
} else if (input is double) {
setDouble(index, input);
} else if (input is num) {
setNum(index, input);
} else if (input is String) {
setString(index, input);
} else if (input is DateTime) {
Expand Down
10 changes: 2 additions & 8 deletions lib/src/resultset.cc
Original file line number Diff line number Diff line change
Expand Up @@ -181,17 +181,11 @@ void OracleResultSet_getDate(Dart_NativeArguments args) {
auto rs = getThis<std::shared_ptr<ResultSet>>(args)->get()->resultSet;
int64_t index = getDartArg<int64_t>(args, 1);

occi::Date date;
try {
if(rs->isNull(index)){
Dart_SetReturnValue(args, Dart_Null());
Dart_ExitScope();
return;
}
date = rs->getDate(index);
occi::Date date = rs->getDate(index);
Dart_SetReturnValue(args, NewDateTimeFromOracleDate(date));
} CATCH_SQL_EXCEPTION

Dart_SetReturnValue(args, NewDateTimeFromOracleDate(date));
Dart_ExitScope();
}

Expand Down
14 changes: 4 additions & 10 deletions lib/src/statement.cc
Original file line number Diff line number Diff line change
Expand Up @@ -210,17 +210,11 @@ void OracleStatement_setDate(Dart_NativeArguments args) {
auto statement = getThis<std::shared_ptr<Statement>>(args)->get()->stmt;
int64_t index = getDartArg<int64_t>(args, 1);

if(nullArg(args,2)){
try{
statement->setNull(index, occi::OCCIDATE);
} CATCH_SQL_EXCEPTION
}else{
auto dartdate = getDartArg<Dart_Handle>(args, 2);
auto dartdate = getDartArg<Dart_Handle>(args, 2);

try {
statement->setDate(index, NewOracleDateFromDateTime(dartdate));
} CATCH_SQL_EXCEPTION
}
try {
statement->setDate(index, NewOracleDateFromDateTime(dartdate));
} CATCH_SQL_EXCEPTION

Dart_ExitScope();
}
Expand Down
43 changes: 42 additions & 1 deletion test/statement_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,48 @@ main() {
expect(rs.getDate(1), null);
});
});
});

group('.setDynamic', () {
test('with String', () {
var stmt = conn.createStatement('INSERT INTO stmt_test (test_string) VALUES (:1)');
expect(() => stmt.setDynamic(1, 'test'), returnsNormally);
});

test('with int', () {
var stmt = conn.createStatement('INSERT INTO stmt_test (test_int) VALUES (:1)');
expect(() => stmt.setDynamic(1, int.parse('5')), returnsNormally);
});

test('with double', () {
var stmt = conn.createStatement('INSERT INTO stmt_test (test_number) VALUES (:1)');
expect(() => stmt.setDynamic(1, double.parse('5.5')), returnsNormally);
});

test('with DateTime', () {
var stmt = conn.createStatement('INSERT INTO stmt_test (test_date) VALUES (:1)');
expect(() => stmt.setDynamic(1, new DateTime.now()), returnsNormally);
});
});

group('.execute', () {
test('with List', () {
helper(colName, argsList) =>
conn.execute('INSERT INTO stmt_test ($colName) VALUES(:1)', argsList);

expect(() => helper('test_string', ['test']), returnsNormally);

expect(() => helper('test_int', [5]), returnsNormally);

expect(() => helper('test_number', [5.5]), returnsNormally);

expect(() => helper('test_date', [new DateTime.now()]), returnsNormally);

// should fail if too many args given
expect(() => helper('test_string', ['test', 5]), throws);
});
});
}); // Statement


test('Connection(username, password, connString)', () {
expect(() => new oracle.Connection(username, password, connString),
Expand Down

0 comments on commit c72c202

Please sign in to comment.