mirror of
https://github.com/gnustep/libs-gdl2.git
synced 2025-04-22 21:00:44 +00:00
* EOAdaptors/SQLite3/SQLite3Channel.m (-evaluateExpression:):
Continue evaluating the expression until all statements are evaluated or rows are returned. * Documentation/GDL2Intro.texi: Add another section on relationships. * Documentation/Examples/library.eomodel: Add relationships as class properties. * Documentation/Examples/GNUmakefile: Add GNUmakefile.eoexample2. * Documentation/Examples/GNUmakefile.eoexample2: New file. * Documentation/Examples/eoexample2.m: New example for relationships. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gdl2/trunk@24319 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
abf9342219
commit
e9e22d054a
7 changed files with 139 additions and 29 deletions
12
ChangeLog
12
ChangeLog
|
@ -1,3 +1,15 @@
|
|||
2007-01-06 Matt Rice <ratmice@gmail.com>
|
||||
|
||||
* EOAdaptors/SQLite3/SQLite3Channel.m (-evaluateExpression:):
|
||||
Continue evaluating the expression until all statements are evaluated
|
||||
or rows are returned.
|
||||
* Documentation/GDL2Intro.texi: Add another section on relationships.
|
||||
* Documentation/Examples/library.eomodel: Add relationships as class
|
||||
properties.
|
||||
* Documentation/Examples/GNUmakefile: Add GNUmakefile.eoexample2.
|
||||
* Documentation/Examples/GNUmakefile.eoexample2: New file.
|
||||
* Documentation/Examples/eoexample2.m: New example for relationships.
|
||||
|
||||
2007-01-05 Matt Rice <ratmice@gmail.com>
|
||||
|
||||
* Documentation/GDL2Intro/GDL2Intro.texi: Add more docs.
|
||||
|
|
|
@ -3,5 +3,6 @@ include $(GNUSTEP_MAKEFILES)/Auxiliary/gdl2.make
|
|||
|
||||
include GNUmakefile.eoexample
|
||||
include GNUmakefile.connection
|
||||
include GNUmakefile.eoexample2
|
||||
|
||||
include $(GNUSTEP_MAKEFILES)/tool.make
|
||||
|
|
4
Documentation/GDL2Intro/Examples/GNUmakefile.eoexample2
Normal file
4
Documentation/GDL2Intro/Examples/GNUmakefile.eoexample2
Normal file
|
@ -0,0 +1,4 @@
|
|||
TOOL_NAME+=eoexample2
|
||||
|
||||
eoexample2_OBJC_FILES=eoexample2.m
|
||||
eoexample2_RESOURCE_FILES=library.eomodel
|
68
Documentation/GDL2Intro/Examples/eoexample2.m
Normal file
68
Documentation/GDL2Intro/Examples/eoexample2.m
Normal file
|
@ -0,0 +1,68 @@
|
|||
#include <Foundation/Foundation.h>
|
||||
#include <EOAccess/EOAccess.h>
|
||||
#include <EOControl/EOControl.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
EOModelGroup *group = [EOModelGroup defaultGroup];
|
||||
EOModel *model;
|
||||
EOAdaptor *adaptor;
|
||||
EOAdaptorContext *context;
|
||||
EOAdaptorChannel *channel;
|
||||
EOEditingContext *ec;
|
||||
EODatabaseDataSource *authorsDS;
|
||||
EODataSource *booksDS;
|
||||
id author;
|
||||
id book;
|
||||
|
||||
model = [group modelNamed:@"library"];
|
||||
|
||||
/* Tools don't have resources so we have to add the model manually */
|
||||
if (!model)
|
||||
{
|
||||
model = [[EOModel alloc] initWithContentsOfFile:@"./library.eomodel"];
|
||||
[group addModel:model];
|
||||
}
|
||||
|
||||
adaptor = [EOAdaptor adaptorWithModel:model];
|
||||
context = [adaptor createAdaptorContext];
|
||||
channel = [context createAdaptorChannel];
|
||||
ec = [[EOEditingContext alloc] init];
|
||||
authorsDS = [[EODatabaseDataSource alloc] initWithEditingContext: ec
|
||||
entityName:@"authors"];
|
||||
|
||||
[channel openChannel];
|
||||
|
||||
author = [authorsDS createObject];
|
||||
[author takeValue:@"Richard Brautigan" forKey:@"name"];
|
||||
[authorsDS insertObject:author];
|
||||
|
||||
booksDS = [authorsDS dataSourceQualifiedByKey:@"toBooks"];
|
||||
[booksDS qualifyWithRelationshipKey:@"toBooks" ofObject:author];
|
||||
|
||||
book = [booksDS createObject];
|
||||
[book takeValue:@"The Hawkline Monster" forKey:@"title"];
|
||||
[booksDS insertObject:book];
|
||||
|
||||
book = [booksDS createObject];
|
||||
[book takeValue:@"Trout Fishing in America" forKey:@"title"];
|
||||
[booksDS insertObject:book];
|
||||
|
||||
[ec saveChanges];
|
||||
|
||||
/* log the to many relationship from author to books */
|
||||
NSLog(@"%@ %@", [author valueForKey:@"name"], [author valueForKeyPath:@"toBooks.title"]);
|
||||
|
||||
/* log the to one relationship from book to author */
|
||||
NSLog(@"%@", [book valueForKeyPath:@"toAuthor.name"]);
|
||||
|
||||
/* traverse to one through the to many through key paths
|
||||
logging the author once for each book. */
|
||||
NSLog(@"%@", [author valueForKeyPath:@"toBooks.toAuthor.name"]);
|
||||
|
||||
[channel closeChannel];
|
||||
[pool release];
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -22,7 +22,8 @@
|
|||
);
|
||||
className = EOGenericRecord;
|
||||
classProperties = (
|
||||
name
|
||||
name,
|
||||
toBooks
|
||||
);
|
||||
externalName = authors;
|
||||
name = authors;
|
||||
|
@ -67,7 +68,8 @@
|
|||
);
|
||||
className = EOGenericRecord;
|
||||
classProperties = (
|
||||
title
|
||||
title,
|
||||
toAuthor
|
||||
);
|
||||
externalName = books;
|
||||
name = books;
|
||||
|
@ -91,4 +93,4 @@
|
|||
}
|
||||
);
|
||||
name = library;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -123,7 +123,7 @@ key in the list.
|
|||
For example,
|
||||
@example
|
||||
@verbatim
|
||||
[anObject valueForKey:@"foo.bar"];
|
||||
[anObject valueForKeyPath:@"foo.bar"];
|
||||
@end verbatim
|
||||
@end example
|
||||
|
||||
|
@ -610,8 +610,7 @@ They export as keys the class properties of the entity, for access and modificat
|
|||
|
||||
If you have an EOGenericRecord from the 'authors' entity
|
||||
of our example model you could set the authors name as so.
|
||||
|
||||
@xref{Example model file}
|
||||
@xref{Example model file}.
|
||||
|
||||
@example
|
||||
@verbatim
|
||||
|
@ -762,13 +761,24 @@ provided you have already created the database in previous section
|
|||
|
||||
@node Working with data
|
||||
@chapter Working with data
|
||||
|
||||
@section Adding some data.
|
||||
Here we have more complete example which writes a record to the database,
|
||||
then fetches the record and updates it and saves the data again.
|
||||
then fetches the record and updates it and saves the data again, then removes the record.
|
||||
|
||||
@example
|
||||
@verbatiminclude Examples/eoexample.m
|
||||
@end example
|
||||
|
||||
@section Working with relationships
|
||||
Heres another more complex example of working with data,
|
||||
we'll add an author, and some books, and then traverse the relationship in
|
||||
a couple of different ways.
|
||||
|
||||
@example
|
||||
@verbatiminclude Examples/eoexample2.m
|
||||
@end example
|
||||
|
||||
@node Index
|
||||
@unnumbered Index
|
||||
|
||||
|
|
|
@ -212,6 +212,7 @@ static id newNumberValue(const unsigned char *data, EOAttribute *attrib)
|
|||
NSString *statement = [sqlExpr statement];
|
||||
int length = [statement length];
|
||||
const char *sql = [statement cString];
|
||||
const char *pzTail = NULL;
|
||||
|
||||
if ([_delegate respondsToSelector:@selector(adaptorChannel:shouldEvaluateExpression:)])
|
||||
if (![_delegate adaptorChannel:self shouldEvaluateExpression:sqlExpr])
|
||||
|
@ -226,31 +227,43 @@ static id newNumberValue(const unsigned char *data, EOAttribute *attrib)
|
|||
sqlite3_finalize(_currentStmt);
|
||||
_currentStmt = NULL;
|
||||
}
|
||||
|
||||
_status = sqlite3_prepare(_sqlite3Conn, sql, length, &_currentStmt, NULL);
|
||||
_isFetchInProgress = sqlite3_column_count(_currentStmt) != 0;
|
||||
|
||||
if (_status != SQLITE_OK)
|
||||
|
||||
while (sql != NULL && (_isFetchInProgress == NO))
|
||||
{
|
||||
_status = sqlite3_finalize(_currentStmt);
|
||||
_currentStmt = NULL;
|
||||
[self _raiseWith:statement];
|
||||
}
|
||||
else
|
||||
{
|
||||
while ((_status = sqlite3_step(_currentStmt)) == SQLITE_BUSY)
|
||||
{
|
||||
// FIXME sleep?
|
||||
}
|
||||
}
|
||||
_status = sqlite3_prepare(_sqlite3Conn, sql, length, &_currentStmt, &pzTail);
|
||||
if (_currentStmt == NULL)
|
||||
{
|
||||
sql = NULL;
|
||||
}
|
||||
|
||||
if (_status != SQLITE_ROW)
|
||||
{
|
||||
sqlite3_finalize(_currentStmt);
|
||||
_currentStmt = NULL;
|
||||
_isFetchInProgress = sqlite3_column_count(_currentStmt) != 0;
|
||||
|
||||
if (_status != SQLITE_OK)
|
||||
{
|
||||
_status = sqlite3_finalize(_currentStmt);
|
||||
_currentStmt = NULL;
|
||||
[self _raiseWith:statement];
|
||||
}
|
||||
else
|
||||
{
|
||||
while ((_status = sqlite3_step(_currentStmt)) == SQLITE_BUSY)
|
||||
{
|
||||
// FIXME sleep?
|
||||
}
|
||||
}
|
||||
|
||||
if (_status != SQLITE_ROW)
|
||||
{
|
||||
sqlite3_finalize(_currentStmt);
|
||||
_currentStmt = NULL;
|
||||
|
||||
if (_status == SQLITE_ERROR)
|
||||
[self _raiseWith:statement];
|
||||
if (_status == SQLITE_ERROR)
|
||||
[self _raiseWith:statement];
|
||||
}
|
||||
|
||||
if (sql)
|
||||
sql = pzTail;
|
||||
pzTail = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue