2004-04-26 15:13:27 +00:00
|
|
|
/**
|
|
|
|
Copyright (C) 2004 Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
Written by: Richard Frith-Macdonald <rfm@gnu.org>
|
|
|
|
Date: April 2004
|
|
|
|
|
|
|
|
This file is part of the SQLClient Library.
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
2007-09-14 13:02:05 +00:00
|
|
|
modify it under the terms of the GNU Lesser General Public
|
2004-04-26 15:13:27 +00:00
|
|
|
License as published by the Free Software Foundation; either
|
2007-09-14 13:02:05 +00:00
|
|
|
version 3 of the License, or (at your option) any later version.
|
2004-04-26 15:13:27 +00:00
|
|
|
|
|
|
|
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
|
2007-09-14 13:02:05 +00:00
|
|
|
Lesser General Public License for more details.
|
2004-04-26 15:13:27 +00:00
|
|
|
|
2007-09-14 13:02:05 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
2004-04-26 15:13:27 +00:00
|
|
|
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$
|
|
|
|
*/
|
|
|
|
|
2007-04-01 08:03:21 +00:00
|
|
|
#import <Foundation/Foundation.h>
|
|
|
|
#import "SQLClient.h"
|
2004-04-26 15:13:27 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
main()
|
|
|
|
{
|
2009-11-18 11:25:01 +00:00
|
|
|
NSAutoreleasePool *pool = [NSAutoreleasePool new];
|
2004-04-26 15:13:27 +00:00
|
|
|
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",
|
|
|
|
@"MySQL", @"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"];
|
2004-05-07 08:16:16 +00:00
|
|
|
[db setDurationLogging: 0];
|
2004-04-26 15:13:27 +00:00
|
|
|
|
|
|
|
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, "
|
|
|
|
@"when2 timestamp"
|
|
|
|
@")",
|
|
|
|
nil];
|
|
|
|
|
|
|
|
[db execute: @"insert into xxx "
|
|
|
|
@"(k, char1, intval, realval, b, when2) "
|
|
|
|
@"values ("
|
|
|
|
@"'hello', "
|
|
|
|
@"'X', "
|
|
|
|
@"1, "
|
|
|
|
@"9.99, ",
|
|
|
|
data, @", ",
|
|
|
|
@"CURRENT_TIMESTAMP",
|
|
|
|
@")",
|
|
|
|
nil];
|
|
|
|
|
|
|
|
[NSThread sleepUntilDate: [NSDate dateWithTimeIntervalSinceNow: 1]];
|
|
|
|
|
|
|
|
[db execute: @"insert into xxx "
|
|
|
|
@"(k, char1, intval, realval, b, when2) "
|
|
|
|
@"values ("
|
|
|
|
@"'hello', "
|
|
|
|
@"'X', "
|
|
|
|
@"1, ",
|
|
|
|
@"12345.6789, ",
|
|
|
|
[NSData dataWithBytes: "" length: 0], @", ",
|
|
|
|
[NSDate date],
|
|
|
|
@")",
|
|
|
|
nil];
|
|
|
|
|
|
|
|
records = [db query: @"select * from xxx", nil];
|
|
|
|
[db execute: @"drop table xxx", nil];
|
|
|
|
|
|
|
|
if ([records count] != 2)
|
|
|
|
{
|
2013-02-11 16:05:47 +00:00
|
|
|
NSLog(@"Expected 2 records but got %" PRIuPTR "", [records count]);
|
2004-04-26 15:13:27 +00:00
|
|
|
}
|
|
|
|
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);
|
|
|
|
|
2009-11-18 11:11:29 +00:00
|
|
|
[pool release];
|
2004-04-26 15:13:27 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|