mirror of
https://github.com/gnustep/libs-sqlclient.git
synced 2025-02-15 16:11:42 +00:00
MacOS-X tweaks
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/sqlclient/trunk@19875 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
04007a38fb
commit
a80dc3830f
2 changed files with 187 additions and 73 deletions
22
GNUmakefile
22
GNUmakefile
|
@ -7,7 +7,7 @@ PACKAGE_NAME = SQLClient
|
|||
TEST_TOOL_NAME = testPostgres testMySQL testECPG
|
||||
testPostgres_OBJC_FILES = testPostgres.m
|
||||
testPostgres_LIB_DIRS += -L./obj
|
||||
testPostgres_TOOL_LIBS += -lSQLClient
|
||||
testPostgres_TOOL_LIBS += -lSQLClient -lpq
|
||||
|
||||
testMySQL_OBJC_FILES = testMySQL.m
|
||||
testMySQL_LIB_DIRS += -L./obj
|
||||
|
@ -20,8 +20,9 @@ testECPG_LIB_DIRS += -L./obj
|
|||
|
||||
LIBRARY_NAME=SQLClient
|
||||
|
||||
SQLClient_OBJC_FILES = SQLClient.m WebServer.m WebServerBundles.m
|
||||
|
||||
SQLClient_OBJC_FILES = SQLClient.m WebServer.m WebServerBundles.m
|
||||
SQLClient_LIBRARIES_DEPEND_UPON =
|
||||
SQLClient_HEADER_FILES = SQLClient.h WebServer.h
|
||||
|
||||
|
||||
|
@ -39,31 +40,34 @@ BUNDLE_INSTALL_DIR=$(GNUSTEP_LOCAL_ROOT)/Library/Bundles/SQLClient
|
|||
ifneq ($(ECPG),)
|
||||
BUNDLE_NAME += ECPG
|
||||
ECPG_OBJC_FILES = ECPG.m
|
||||
ECPG_BUNDLE_LIBS += -L./obj -lSQLClient -lgnustep-base -lobjc -lecpg
|
||||
ECPG_LDFLAGS = -L./obj
|
||||
ECPG_BUNDLE_LIBS += -lSQLClient -lecpg
|
||||
ECPG_PRINCIPAL_CLASS = SQLClientECPG
|
||||
endif
|
||||
|
||||
ifneq ($(POSTGRES),)
|
||||
BUNDLE_NAME += Postgres
|
||||
Postgres_OBJC_FILES = Postgres.m
|
||||
Postgres_BUNDLE_LIBS += -L./obj -lSQLClient -lgnustep-base -lobjc -lpq
|
||||
Postgres_LDFLAGS = -L./obj
|
||||
Postgres_BUNDLE_LIBS += -lSQLClient -lpq
|
||||
Postgres_PRINCIPAL_CLASS = SQLClientPostgres
|
||||
endif
|
||||
|
||||
ifneq ($(MYSQL),)
|
||||
BUNDLE_NAME += MySQL
|
||||
MySQL_OBJC_FILES = MySQL.m
|
||||
MySQL_BUNDLE_LIBS += -L./obj -lSQLClient -lgnustep-base -lobjc -lmysqlclient
|
||||
MySQL_LDFLAGS = -L./obj
|
||||
MySQL_BUNDLE_LIBS += -lSQLClient -lmysqlclient
|
||||
MySQL_PRINCIPAL_CLASS = SQLClientMySQL
|
||||
endif
|
||||
|
||||
ifneq ($(ORACLE_HOME),)
|
||||
BUNDLE_NAME += Oracle
|
||||
Oracle_OBJC_FILES = Oracle.m
|
||||
Oracle_BUNDLE_LIBS += -L$(ORACLE_HOME)/lib \
|
||||
-lclntsh \
|
||||
-L./obj -lSQLClient -lgnustep-base -lobjc \
|
||||
$(shell cat $(ORACLE_HOME)/lib/ldflags) \
|
||||
Oracle_LDFLAGS = -L$(ORACLE_HOME)/lib -L./obj \
|
||||
$(shell cat $(ORACLE_HOME)/lib/ldflags)
|
||||
Oracle_BUNDLE_LIBS += -lclntsh \
|
||||
-lSQLClient \
|
||||
$(shell cat $(ORACLE_HOME)/lib/sysliblist) \
|
||||
-ldl -lm
|
||||
Oracle_PRINCIPAL_CLASS = SQLClientOracle
|
||||
|
|
238
testPostgres.m
238
testPostgres.m
|
@ -37,6 +37,7 @@ main()
|
|||
unsigned char dbuf[256];
|
||||
unsigned int i;
|
||||
NSData *data;
|
||||
NSString *name;
|
||||
|
||||
defs = [NSUserDefaults standardUserDefaults];
|
||||
[defs registerDefaults:
|
||||
|
@ -54,79 +55,188 @@ main()
|
|||
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), "
|
||||
@"boolval BOOL, "
|
||||
@"intval int, "
|
||||
@"when1 timestamp with time zone, "
|
||||
@"when2 timestamp, "
|
||||
@"b bytea"
|
||||
@")",
|
||||
nil];
|
||||
|
||||
[db execute: @"insert into xxx "
|
||||
@"(k, char1, boolval, intval, when1, when2, b) "
|
||||
@"values ("
|
||||
@"'hello', "
|
||||
@"'X', "
|
||||
@"TRUE, "
|
||||
@"1, "
|
||||
@"CURRENT_TIMESTAMP, "
|
||||
@"CURRENT_TIMESTAMP, ",
|
||||
data,
|
||||
@")",
|
||||
nil];
|
||||
[db execute: @"insert into xxx "
|
||||
@"(k, char1, boolval, intval, when1, when2, b) "
|
||||
@"values ("
|
||||
@"'hello', "
|
||||
@"'X', "
|
||||
@"TRUE, "
|
||||
@"1, ",
|
||||
[NSDate date], @", ",
|
||||
[NSDate date], @", ",
|
||||
[NSData dataWithBytes: "" length: 0],
|
||||
@")",
|
||||
nil];
|
||||
|
||||
records = [db query: @"select * from xxx", nil];
|
||||
[db execute: @"drop table xxx", nil];
|
||||
|
||||
if ([records count] != 2)
|
||||
if ((name = [defs stringForKey: @"Producer"]) != nil)
|
||||
{
|
||||
NSLog(@"Expected 2 records but got %u", [records count]);
|
||||
NS_DURING
|
||||
{
|
||||
[db execute: @"CREATE TABLE Queue ( "
|
||||
@"ID SERIAL, "
|
||||
@"Consumer CHAR(40) NOT NULL, "
|
||||
@"ServiceID INT NOT NULL, "
|
||||
@"Status CHAR(1) DEFAULT 'Q' NOT NULL, "
|
||||
@"Delivery TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, "
|
||||
@"Reference CHAR(128), "
|
||||
@"Destination CHAR(15) NOT NULL, "
|
||||
@"Payload CHAR(250) DEFAULT '' NOT NULL"
|
||||
@")",
|
||||
nil];
|
||||
[db execute:
|
||||
@"CREATE UNIQUE INDEX QueueIDX ON Queue (ID)",
|
||||
nil];
|
||||
[db execute:
|
||||
@"CREATE INDEX ServiceIDX ON Queue (ServiceID)",
|
||||
nil];
|
||||
[db execute:
|
||||
@"CREATE INDEX ConsumerIDX ON Queue (Consumer,Status,Delivery)",
|
||||
nil];
|
||||
[db execute:
|
||||
@"CREATE INDEX ReferenceIDX ON Queue (Reference,Consumer)",
|
||||
nil];
|
||||
}
|
||||
NS_HANDLER
|
||||
{
|
||||
NSLog(@"%@", localException);
|
||||
}
|
||||
NS_ENDHANDLER
|
||||
NSLog(@"Start producing");
|
||||
for (i = 0; i < 100000; i++)
|
||||
{
|
||||
CREATE_AUTORELEASE_POOL(arp);
|
||||
NSString *destination = [NSString stringWithFormat: @"%d", i];
|
||||
NSString *sid = [NSString stringWithFormat: @"%d", i%100];
|
||||
|
||||
[db execute: @"INSERT INTO Queue (Consumer, Destination, ServiceID, Payload) VALUES (",
|
||||
[db quote: name], @", ", [db quote: destination], @", ", sid, @", ",
|
||||
@"'helo there'", @")", nil];
|
||||
RELEASE(arp);
|
||||
}
|
||||
NSLog(@"End producing");
|
||||
}
|
||||
else if ((name = [defs stringForKey: @"Consumer"]) != nil)
|
||||
{
|
||||
NSLog(@"Start consuming");
|
||||
for (i = 0; i < 100000;)
|
||||
{
|
||||
CREATE_AUTORELEASE_POOL(arp);
|
||||
unsigned count;
|
||||
int j;
|
||||
|
||||
[db begin];
|
||||
records = [db query: @"SELECT * FROM Queue WHERE Consumer = ",
|
||||
[db quote: name],
|
||||
@" AND Status = 'Q' AND Delivery < CURRENT_TIMESTAMP",
|
||||
@" ORDER BY Delivery LIMIT 1000 FOR UPDATE" , nil];
|
||||
count = [records count];
|
||||
if (count == 0)
|
||||
{
|
||||
[db commit];
|
||||
sleep(1);
|
||||
[db begin];
|
||||
records = [db query: @"SELECT * FROM Queue WHERE Consumer = ",
|
||||
[db quote: name],
|
||||
@" AND Status = 'Q' AND Delivery < CURRENT_TIMESTAMP",
|
||||
@" ORDER BY Delivery LIMIT 50 FOR UPDATE" , nil];
|
||||
count = [records count];
|
||||
if (count == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (j = 0; j < count; j++)
|
||||
{
|
||||
SQLRecord *record = [records objectAtIndex: j];
|
||||
NSString *reference = [record objectForKey: @"ID"];
|
||||
|
||||
[db execute: @"UPDATE Queue SET Status = 'S', Reference = ",
|
||||
[db quote: reference], @" WHERE ID = ",
|
||||
[record objectForKey: @"ID"], nil];
|
||||
|
||||
[db execute: @"UPDATE Queue SET Status = 'D'",
|
||||
@" WHERE Consumer = ", [db quote: name],
|
||||
@" AND Reference = ", [db quote: reference],
|
||||
nil];
|
||||
}
|
||||
[db commit];
|
||||
i += count;
|
||||
RELEASE(arp);
|
||||
}
|
||||
NSLog(@"End consuming (%d records)", i);
|
||||
/*
|
||||
[db execute: @"DROP INDEX ReferenceIDX", nil];
|
||||
[db execute: @"DROP INDEX ServiceIDX", nil];
|
||||
[db execute: @"DROP INDEX ConsumerIDX", nil];
|
||||
[db execute: @"DROP INDEX QueueIDX", nil];
|
||||
[db execute: @"DROP TABLE Queue", nil];
|
||||
*/
|
||||
}
|
||||
else
|
||||
{
|
||||
record = [records objectAtIndex: 0];
|
||||
if ([[record objectForKey: @"b"] isEqual: data] == NO)
|
||||
for (i = 0; i < 256; i++)
|
||||
{
|
||||
NSLog(@"Retrieved data does not match saved data %@ %@",
|
||||
data, [record objectForKey: @"b"]);
|
||||
dbuf[i] = i;
|
||||
}
|
||||
record = [records objectAtIndex: 1];
|
||||
if ([[record objectForKey: @"b"] isEqual: [NSData data]] == NO)
|
||||
{
|
||||
NSLog(@"Retrieved empty data does not match saved data");
|
||||
}
|
||||
}
|
||||
data = [NSData dataWithBytes: dbuf length: i];
|
||||
|
||||
NSLog(@"Records - %@", records);
|
||||
NS_DURING
|
||||
[db execute: @"drop table xxx", nil];
|
||||
NS_HANDLER
|
||||
NS_ENDHANDLER
|
||||
|
||||
[db setDurationLogging: 0];
|
||||
|
||||
[db execute: @"create table xxx ( "
|
||||
@"k char(40), "
|
||||
@"char1 char(1), "
|
||||
@"boolval BOOL, "
|
||||
@"intval int, "
|
||||
@"when1 timestamp with time zone, "
|
||||
@"when2 timestamp, "
|
||||
@"b bytea"
|
||||
@")",
|
||||
nil];
|
||||
|
||||
[db execute: @"insert into xxx "
|
||||
@"(k, char1, boolval, intval, when1, when2, b) "
|
||||
@"values ("
|
||||
@"'hello', "
|
||||
@"'X', "
|
||||
@"TRUE, "
|
||||
@"1, "
|
||||
@"CURRENT_TIMESTAMP, "
|
||||
@"CURRENT_TIMESTAMP, ",
|
||||
data,
|
||||
@")",
|
||||
nil];
|
||||
[db execute: @"insert into xxx "
|
||||
@"(k, char1, boolval, intval, when1, when2, b) "
|
||||
@"values ("
|
||||
@"'hello', "
|
||||
@"'X', "
|
||||
@"TRUE, "
|
||||
@"1, ",
|
||||
[NSDate date], @", ",
|
||||
[NSDate date], @", ",
|
||||
[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