mirror of
https://github.com/gnustep/libs-sqlclient.git
synced 2025-02-15 16:11:42 +00:00
Added test program
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/sqlclient/trunk@22083 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
28f053a7fb
commit
9d547523eb
2 changed files with 140 additions and 2 deletions
13
SQLite.m
13
SQLite.m
|
@ -211,7 +211,7 @@
|
|||
char *statement;
|
||||
int result;
|
||||
sqlite3_stmt *prepared;
|
||||
const char *prepEnd;
|
||||
const char *stmtEnd;
|
||||
|
||||
/*
|
||||
* Ensure we have a working connection.
|
||||
|
@ -225,7 +225,7 @@
|
|||
|
||||
statement = (char*)[stmt UTF8String];
|
||||
result = sqlite3_prepare((sqlite3 *)extra,
|
||||
statement, -1, &prepared, &prepEnd);
|
||||
statement, strlen(statement), &prepared, &stmtEnd);
|
||||
if (result != SQLITE_OK)
|
||||
{
|
||||
[NSException raise: SQLException
|
||||
|
@ -349,5 +349,14 @@ static char hex[16] = "0123456789ABCDEF";
|
|||
return 3 + [blob length] * 2;
|
||||
}
|
||||
|
||||
- (NSString*) quote: (id)obj
|
||||
{
|
||||
if ([obj isKindOfClass: [NSDate class]] == YES)
|
||||
{
|
||||
obj = [NSNumber numberWithDouble: [obj timeIntervalSinceReferenceDate]];
|
||||
}
|
||||
return [super quote: obj];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
|
129
testSQLite.m
Normal file
129
testSQLite.m
Normal file
|
@ -0,0 +1,129 @@
|
|||
/**
|
||||
Copyright (C) 2005 Free Software Foundation, Inc.
|
||||
|
||||
Written by: Richard Frith-Macdonald <rfm@gnu.org>
|
||||
Date: April 2005
|
||||
|
||||
This file is part of the SQLClient Library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
||||
|
||||
$Date$ $Revision$
|
||||
*/
|
||||
|
||||
#include <Foundation/Foundation.h>
|
||||
#include "SQLClient.h"
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
CREATE_AUTORELEASE_POOL(pool);
|
||||
SQLClient *db;
|
||||
NSUserDefaults *defs;
|
||||
NSMutableArray *records;
|
||||
SQLRecord *record;
|
||||
unsigned char dbuf[256];
|
||||
unsigned int i;
|
||||
NSData *data;
|
||||
|
||||
defs = [NSUserDefaults standardUserDefaults];
|
||||
[defs registerDefaults:
|
||||
[NSDictionary dictionaryWithObjectsAndKeys:
|
||||
[NSDictionary dictionaryWithObjectsAndKeys:
|
||||
[NSDictionary dictionaryWithObjectsAndKeys:
|
||||
@"test", @"Database",
|
||||
@"", @"User",
|
||||
@"", @"Password",
|
||||
@"SQLite", @"ServerType",
|
||||
nil],
|
||||
@"test",
|
||||
nil],
|
||||
@"SQLClientReferences",
|
||||
nil]
|
||||
];
|
||||
|
||||
for (i = 0; i < 256; i++)
|
||||
{
|
||||
dbuf[i] = i;
|
||||
}
|
||||
data = [NSData dataWithBytes: dbuf length: i];
|
||||
|
||||
db = [SQLClient clientWithConfiguration: nil name: @"test"];
|
||||
[db setDurationLogging: 0];
|
||||
|
||||
NS_DURING
|
||||
[db execute: @"drop table xxx", nil];
|
||||
NS_HANDLER
|
||||
NS_ENDHANDLER
|
||||
|
||||
[db execute: @"create table xxx ( "
|
||||
@"k char(40), "
|
||||
@"char1 char(1), "
|
||||
@"intval int, "
|
||||
@"realval real, "
|
||||
@"b blob)",
|
||||
nil];
|
||||
|
||||
[db execute: @"insert into xxx "
|
||||
@"(k, char1, intval, realval, b) "
|
||||
@"values ("
|
||||
@"'hello', "
|
||||
@"'X', "
|
||||
@"1, "
|
||||
@"9.99, ",
|
||||
data,
|
||||
@")",
|
||||
nil];
|
||||
|
||||
[NSThread sleepUntilDate: [NSDate dateWithTimeIntervalSinceNow: 1]];
|
||||
|
||||
[db execute: @"insert into xxx "
|
||||
@"(k, char1, intval, realval, b) "
|
||||
@"values ("
|
||||
@"'hello', "
|
||||
@"'X', "
|
||||
@"1, ",
|
||||
@"12345.6789, ",
|
||||
[NSData dataWithBytes: "" length: 0], @")",
|
||||
nil];
|
||||
|
||||
records = [db query: @"select * from xxx", nil];
|
||||
[db execute: @"drop table xxx", nil];
|
||||
|
||||
if ([records count] != 2)
|
||||
{
|
||||
NSLog(@"Expected 2 records but got %u", [records count]);
|
||||
}
|
||||
else
|
||||
{
|
||||
record = [records objectAtIndex: 0];
|
||||
if ([[record objectForKey: @"b"] isEqual: data] == NO)
|
||||
{
|
||||
NSLog(@"Retrieved data does not match saved data %@ %@",
|
||||
data, [record objectForKey: @"b"]);
|
||||
}
|
||||
record = [records objectAtIndex: 1];
|
||||
if ([[record objectForKey: @"b"] isEqual: [NSData data]] == NO)
|
||||
{
|
||||
NSLog(@"Retrieved empty data does not match saved data");
|
||||
}
|
||||
}
|
||||
|
||||
NSLog(@"Records - %@", records);
|
||||
|
||||
RELEASE(pool);
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in a new issue