--- /dev/null
+ GNU LIBRARY GENERAL PUBLIC LICENSE
+ Version 2, June 1991
+
+ Copyright (C) 1991 Free Software Foundation, Inc.
+ 675 Mass Ave, Cambridge, MA 02139, USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+[This is the first released version of the library GPL. It is
+ numbered 2 because it goes with version 2 of the ordinary GPL.]
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+Licenses are intended to guarantee your freedom to share and change
+free software--to make sure the software is free for all its users.
+
+ This license, the Library General Public License, applies to some
+specially designated Free Software Foundation software, and to any
+other libraries whose authors decide to use it. You can use it for
+your libraries, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+ To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if
+you distribute copies of the library, or if you modify it.
+
+ For example, if you distribute copies of the library, whether gratis
+or for a fee, you must give the recipients all the rights that we gave
+you. You must make sure that they, too, receive or can get the source
+code. If you link a program with the library, you must provide
+complete object files to the recipients so that they can relink them
+with the library, after making changes to the library and recompiling
+it. And you must show them these terms so they know their rights.
+
+ Our method of protecting your rights has two steps: (1) copyright
+the library, and (2) offer you this license which gives you legal
+permission to copy, distribute and/or modify the library.
+
+ Also, for each distributor's protection, we want to make certain
+that everyone understands that there is no warranty for this free
+library. If the library is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original
+version, so that any problems introduced by others will not reflect on
+the original authors' reputations.
+\f
+ Finally, any free program is threatened constantly by software
+patents. We wish to avoid the danger that companies distributing free
+software will individually obtain patent licenses, thus in effect
+transforming the program into proprietary software. To prevent this,
+we have made it clear that any patent must be licensed for everyone's
+free use or not licensed at all.
+
+ Most GNU software, including some libraries, is covered by the ordinary
+GNU General Public License, which was designed for utility programs. This
+license, the GNU Library General Public License, applies to certain
+designated libraries. This license is quite different from the ordinary
+one; be sure to read it in full, and don't assume that anything in it is
+the same as in the ordinary license.
+
+ The reason we have a separate public license for some libraries is that
+they blur the distinction we usually make between modifying or adding to a
+program and simply using it. Linking a program with a library, without
+changing the library, is in some sense simply using the library, and is
+analogous to running a utility program or application program. However, in
+a textual and legal sense, the linked executable is a combined work, a
+derivative of the original library, and the ordinary General Public License
+treats it as such.
+
+ Because of this blurred distinction, using the ordinary General
+Public License for libraries did not effectively promote software
+sharing, because most developers did not use the libraries. We
+concluded that weaker conditions might promote sharing better.
+
+ However, unrestricted linking of non-free programs would deprive the
+users of those programs of all benefit from the free status of the
+libraries themselves. This Library General Public License is intended to
+permit developers of non-free programs to use free libraries, while
+preserving your freedom as a user of such programs to change the free
+libraries that are incorporated in them. (We have not seen how to achieve
+this as regards changes in header files, but we have achieved it as regards
+changes in the actual functions of the Library.) The hope is that this
+will lead to faster development of free libraries.
+
+ The precise terms and conditions for copying, distribution and
+modification follow. Pay close attention to the difference between a
+"work based on the library" and a "work that uses the library". The
+former contains code derived from the library, while the latter only
+works together with the library.
+
+ Note that it is possible for a library to be covered by the ordinary
+General Public License rather than by this special one.
+\f
+ GNU LIBRARY GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License Agreement applies to any software library which
+contains a notice placed by the copyright holder or other authorized
+party saying it may be distributed under the terms of this Library
+General Public License (also called "this License"). Each licensee is
+addressed as "you".
+
+ A "library" means a collection of software functions and/or data
+prepared so as to be conveniently linked with application programs
+(which use some of those functions and data) to form executables.
+
+ The "Library", below, refers to any such software library or work
+which has been distributed under these terms. A "work based on the
+Library" means either the Library or any derivative work under
+copyright law: that is to say, a work containing the Library or a
+portion of it, either verbatim or with modifications and/or translated
+straightforwardly into another language. (Hereinafter, translation is
+included without limitation in the term "modification".)
+
+ "Source code" for a work means the preferred form of the work for
+making modifications to it. For a library, complete source code means
+all the source code for all modules it contains, plus any associated
+interface definition files, plus the scripts used to control compilation
+and installation of the library.
+
+ Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running a program using the Library is not restricted, and output from
+such a program is covered only if its contents constitute a work based
+on the Library (independent of the use of the Library in a tool for
+writing it). Whether that is true depends on what the Library does
+and what the program that uses the Library does.
+
+ 1. You may copy and distribute verbatim copies of the Library's
+complete source code as you receive it, in any medium, provided that
+you conspicuously and appropriately publish on each copy an
+appropriate copyright notice and disclaimer of warranty; keep intact
+all the notices that refer to this License and to the absence of any
+warranty; and distribute a copy of this License along with the
+Library.
+
+ You may charge a fee for the physical act of transferring a copy,
+and you may at your option offer warranty protection in exchange for a
+fee.
+\f
+ 2. You may modify your copy or copies of the Library or any portion
+of it, thus forming a work based on the Library, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) The modified work must itself be a software library.
+
+ b) You must cause the files modified to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ c) You must cause the whole of the work to be licensed at no
+ charge to all third parties under the terms of this License.
+
+ d) If a facility in the modified Library refers to a function or a
+ table of data to be supplied by an application program that uses
+ the facility, other than as an argument passed when the facility
+ is invoked, then you must make a good faith effort to ensure that,
+ in the event an application does not supply such function or
+ table, the facility still operates, and performs whatever part of
+ its purpose remains meaningful.
+
+ (For example, a function in a library to compute square roots has
+ a purpose that is entirely well-defined independent of the
+ application. Therefore, Subsection 2d requires that any
+ application-supplied function or table used by this function must
+ be optional: if the application does not supply it, the square
+ root function must still compute square roots.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Library,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Library, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote
+it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Library.
+
+In addition, mere aggregation of another work not based on the Library
+with the Library (or with a work based on the Library) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may opt to apply the terms of the ordinary GNU General Public
+License instead of this License to a given copy of the Library. To do
+this, you must alter all the notices that refer to this License, so
+that they refer to the ordinary GNU General Public License, version 2,
+instead of to this License. (If a newer version than version 2 of the
+ordinary GNU General Public License has appeared, then you can specify
+that version instead if you wish.) Do not make any other change in
+these notices.
+\f
+ Once this change is made in a given copy, it is irreversible for
+that copy, so the ordinary GNU General Public License applies to all
+subsequent copies and derivative works made from that copy.
+
+ This option is useful when you wish to copy part of the code of
+the Library into a program that is not a library.
+
+ 4. You may copy and distribute the Library (or a portion or
+derivative of it, under Section 2) in object code or executable form
+under the terms of Sections 1 and 2 above provided that you accompany
+it with the complete corresponding machine-readable source code, which
+must be distributed under the terms of Sections 1 and 2 above on a
+medium customarily used for software interchange.
+
+ If distribution of object code is made by offering access to copy
+from a designated place, then offering equivalent access to copy the
+source code from the same place satisfies the requirement to
+distribute the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 5. A program that contains no derivative of any portion of the
+Library, but is designed to work with the Library by being compiled or
+linked with it, is called a "work that uses the Library". Such a
+work, in isolation, is not a derivative work of the Library, and
+therefore falls outside the scope of this License.
+
+ However, linking a "work that uses the Library" with the Library
+creates an executable that is a derivative of the Library (because it
+contains portions of the Library), rather than a "work that uses the
+library". The executable is therefore covered by this License.
+Section 6 states terms for distribution of such executables.
+
+ When a "work that uses the Library" uses material from a header file
+that is part of the Library, the object code for the work may be a
+derivative work of the Library even though the source code is not.
+Whether this is true is especially significant if the work can be
+linked without the Library, or if the work is itself a library. The
+threshold for this to be true is not precisely defined by law.
+
+ If such an object file uses only numerical parameters, data
+structure layouts and accessors, and small macros and small inline
+functions (ten lines or less in length), then the use of the object
+file is unrestricted, regardless of whether it is legally a derivative
+work. (Executables containing this object code plus portions of the
+Library will still fall under Section 6.)
+
+ Otherwise, if the work is a derivative of the Library, you may
+distribute the object code for the work under the terms of Section 6.
+Any executables containing that work also fall under Section 6,
+whether or not they are linked directly with the Library itself.
+\f
+ 6. As an exception to the Sections above, you may also compile or
+link a "work that uses the Library" with the Library to produce a
+work containing portions of the Library, and distribute that work
+under terms of your choice, provided that the terms permit
+modification of the work for the customer's own use and reverse
+engineering for debugging such modifications.
+
+ You must give prominent notice with each copy of the work that the
+Library is used in it and that the Library and its use are covered by
+this License. You must supply a copy of this License. If the work
+during execution displays copyright notices, you must include the
+copyright notice for the Library among them, as well as a reference
+directing the user to the copy of this License. Also, you must do one
+of these things:
+
+ a) Accompany the work with the complete corresponding
+ machine-readable source code for the Library including whatever
+ changes were used in the work (which must be distributed under
+ Sections 1 and 2 above); and, if the work is an executable linked
+ with the Library, with the complete machine-readable "work that
+ uses the Library", as object code and/or source code, so that the
+ user can modify the Library and then relink to produce a modified
+ executable containing the modified Library. (It is understood
+ that the user who changes the contents of definitions files in the
+ Library will not necessarily be able to recompile the application
+ to use the modified definitions.)
+
+ b) Accompany the work with a written offer, valid for at
+ least three years, to give the same user the materials
+ specified in Subsection 6a, above, for a charge no more
+ than the cost of performing this distribution.
+
+ c) If distribution of the work is made by offering access to copy
+ from a designated place, offer equivalent access to copy the above
+ specified materials from the same place.
+
+ d) Verify that the user has already received a copy of these
+ materials or that you have already sent this user a copy.
+
+ For an executable, the required form of the "work that uses the
+Library" must include any data and utility programs needed for
+reproducing the executable from it. However, as a special exception,
+the source code distributed need not include anything that is normally
+distributed (in either source or binary form) with the major
+components (compiler, kernel, and so on) of the operating system on
+which the executable runs, unless that component itself accompanies
+the executable.
+
+ It may happen that this requirement contradicts the license
+restrictions of other proprietary libraries that do not normally
+accompany the operating system. Such a contradiction means you cannot
+use both them and the Library together in an executable that you
+distribute.
+\f
+ 7. You may place library facilities that are a work based on the
+Library side-by-side in a single library together with other library
+facilities not covered by this License, and distribute such a combined
+library, provided that the separate distribution of the work based on
+the Library and of the other library facilities is otherwise
+permitted, and provided that you do these two things:
+
+ a) Accompany the combined library with a copy of the same work
+ based on the Library, uncombined with any other library
+ facilities. This must be distributed under the terms of the
+ Sections above.
+
+ b) Give prominent notice with the combined library of the fact
+ that part of it is a work based on the Library, and explaining
+ where to find the accompanying uncombined form of the same work.
+
+ 8. You may not copy, modify, sublicense, link with, or distribute
+the Library except as expressly provided under this License. Any
+attempt otherwise to copy, modify, sublicense, link with, or
+distribute the Library is void, and will automatically terminate your
+rights under this License. However, parties who have received copies,
+or rights, from you under this License will not have their licenses
+terminated so long as such parties remain in full compliance.
+
+ 9. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Library or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Library (or any work based on the
+Library), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Library or works based on it.
+
+ 10. Each time you redistribute the Library (or any work based on the
+Library), the recipient automatically receives a license from the
+original licensor to copy, distribute, link with or modify the Library
+subject to these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+\f
+ 11. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Library at all. For example, if a patent
+license would not permit royalty-free redistribution of the Library by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Library.
+
+If any portion of this section is held invalid or unenforceable under any
+particular circumstance, the balance of the section is intended to apply,
+and the section as a whole is intended to apply in other circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 12. If the distribution and/or use of the Library is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Library under this License may add
+an explicit geographical distribution limitation excluding those countries,
+so that distribution is permitted only in or among countries not thus
+excluded. In such case, this License incorporates the limitation as if
+written in the body of this License.
+
+ 13. The Free Software Foundation may publish revised and/or new
+versions of the Library General Public License from time to time.
+Such new versions will be similar in spirit to the present version,
+but may differ in detail to address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Library
+specifies a version number of this License which applies to it and
+"any later version", you have the option of following the terms and
+conditions either of that version or of any later version published by
+the Free Software Foundation. If the Library does not specify a
+license version number, you may choose any version ever published by
+the Free Software Foundation.
+\f
+ 14. If you wish to incorporate parts of the Library into other free
+programs whose distribution conditions are incompatible with these,
+write to the author to ask for permission. For software which is
+copyrighted by the Free Software Foundation, write to the Free
+Software Foundation; we sometimes make exceptions for this. Our
+decision will be guided by the two goals of preserving the free status
+of all derivatives of our free software and of promoting the sharing
+and reuse of software generally.
+
+ NO WARRANTY
+
+ 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
+WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
+EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
+OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
+KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
+LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
+THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+ 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
+WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
+AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
+FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
+CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
+LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
+RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
+FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
+SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
+DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+\f
+ Appendix: How to Apply These Terms to Your New Libraries
+
+ If you develop a new library, and you want it to be of the greatest
+possible use to the public, we recommend making it free software that
+everyone can redistribute and change. You can do so by permitting
+redistribution under these terms (or, alternatively, under the terms of the
+ordinary General Public License).
+
+ To apply these terms, attach the following notices to the library. It is
+safest to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least the
+"copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the library's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+Also add information on how to contact you by electronic and paper mail.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the library, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the
+ library `Frob' (a library for tweaking knobs) written by James Random Hacker.
+
+ <signature of Ty Coon>, 1 April 1990
+ Ty Coon, President of Vice
+
+That's all there is to it!
--- /dev/null
+2005-02-20 Helge Hess <helge.hess@opengroupware.org>
+
+ * added work on the SQLite3 adaptor to SOPE 4.5 repository
+
+ * removed some PostgreSQL stuff
+
+ * created ChangeLog
--- /dev/null
+/*
+ EOAttribute+SQLite.h
+
+ Copyright (C) 2003-2004 Helge Hess
+
+ Author: Helge Hess (helge.hess@opengroupware.org)
+
+ This file is part of the SQLite Adaptor 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; see the file COPYING.LIB.
+ If not, write to the Free Software Foundation,
+ 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+
+#ifndef ___SQLite_EOAttribute_H___
+#define ___SQLite_EOAttribute_H___
+
+#import <GDLAccess/EOAttribute.h>
+#include <sqlite3.h>
+
+@class NSString;
+
+@interface EOAttribute(SQLiteAttributeAdditions)
+
+- (void)loadValueClassAndTypeUsingSQLiteType:(int)_type
+ size:(int)_size
+ modification:(int)_modification
+ binary:(BOOL)_isBinary;
+
+- (void)loadValueClassForExternalSQLiteType:(NSString *)_type;
+
+@end
+
+#endif /* ___SQLite_EOAttribute_H___ */
--- /dev/null
+/*
+ EOAttribute+SQLite.m
+
+ Copyright (C) 1999 MDlink online service center GmbH and Helge Hess
+
+ Author: Helge Hess (helge@mdlink.de)
+
+ This file is part of the SQLite Adaptor 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; see the file COPYING.LIB.
+ If not, write to the Free Software Foundation,
+ 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+
+#include "common.h"
+#import "EOAttribute+SQLite.h"
+
+static NSString *SQLITE3_DATETIME_FORMAT = @"%b %d %Y %I:%M:%S:000%p";
+static NSString *SQLITE3_TIMESTAMP_FORMAT = @"%Y-%m-%d %H:%M:%S%z";
+
+@implementation EOAttribute(SQLiteAttributeAdditions)
+
+- (void)loadValueClassAndTypeUsingSQLiteType:(int)_type
+ size:(int)_size
+ modification:(int)_modification
+ binary:(BOOL)_isBinary
+{
+ /* This method makes no sense with SQLite? */
+
+ if (_isBinary)
+ [self setValueClassName:@"NSData"];
+
+#if 0
+ switch (_type) {
+ case BOOLOID:
+ [self setExternalType:@"bool"];
+ [self setValueClassName:@"NSNumber"];
+ [self setValueType:@"i"];
+ return;
+ case NAMEOID:
+ [self setExternalType:@"name"];
+ [self setValueClassName:@"NSString"];
+ return;
+ case TEXTOID:
+ [self setExternalType:@"textoid"];
+ [self setValueClassName:@"NSString"];
+ return;
+ case INT2OID:
+ [self setExternalType:@"int2"];
+ [self setValueClassName:@"NSNumber"];
+ [self setValueType:@"d"];
+ return;
+ case INT4OID:
+ [self setExternalType:@"int4"];
+ [self setValueClassName:@"NSNumber"];
+ [self setValueType:@"d"];
+ return;
+ case INT8OID:
+ [self setExternalType:@"int8"];
+ [self setValueClassName:@"NSNumber"];
+ [self setValueType:@"d"];
+ return;
+
+ case CHAROID:
+ [self setExternalType:@"char"];
+ [self setValueClassName:@"NSString"];
+ break;
+ case VARCHAROID:
+ [self setExternalType:@"varchar"];
+ [self setValueClassName:@"NSString"];
+ break;
+ case NUMERICOID:
+ [self setExternalType:@"numeric"];
+ [self setValueClassName:@"NSNumber"];
+ [self setValueType:@"d"];
+ break;
+ case FLOAT4OID:
+ [self setExternalType:@"float4"];
+ [self setValueClassName:@"NSNumber"];
+ [self setValueType:@"f"];
+ break;
+ case FLOAT8OID:
+ [self setExternalType:@"float8"];
+ [self setValueClassName:@"NSNumber"];
+ [self setValueType:@"f"];
+ break;
+
+ case DATEOID:
+ [self setExternalType:@"datetime"];
+ [self setValueClassName:@"NSCalendarDate"];
+ [self setCalendarFormat:SQLITE3_DATETIME_FORMAT];
+ break;
+ case TIMEOID:
+ [self setExternalType:@"time"];
+ [self setValueClassName:@"NSCalendarDate"];
+ [self setCalendarFormat:SQLITE3_DATETIME_FORMAT];
+ break;
+ case TIMESTAMPOID:
+ [self setExternalType:@"timestamp"];
+ [self setValueClassName:@"NSCalendarDate"];
+ [self setCalendarFormat:SQLITE3_DATETIME_FORMAT];
+ break;
+ case TIMESTAMPTZOID:
+ [self setExternalType:@"timestamptz"];
+ [self setValueClassName:@"NSCalendarDate"];
+ [self setCalendarFormat:SQLITE3_DATETIME_FORMAT];
+ break;
+ case BITOID:
+ [self setExternalType:@"bit"];
+ break;
+ default:
+ NSLog(@"What is SQLITE3 Oid %i ???", _type);
+ break;
+ }
+#endif
+}
+
+- (void)loadValueClassForExternalSQLiteType:(NSString *)_type {
+ if ([_type isEqualToString:@"bool"]) {
+ [self setValueClassName:@"NSNumber"];
+ [self setValueType:@"i"];
+ }
+ else if ([_type isEqualToString:@"int2"]) {
+ [self setValueClassName:@"NSNumber"];
+ [self setValueType:@"i"];
+ }
+ else if ([_type isEqualToString:@"int4"]) {
+ [self setValueClassName:@"NSNumber"];
+ [self setValueType:@"i"];
+ }
+ else if ([_type isEqualToString:@"float4"]) {
+ [self setValueClassName:@"NSNumber"];
+ [self setValueType:@"f"];
+ }
+ else if ([_type isEqualToString:@"float8"]) {
+ [self setValueClassName:@"NSNumber"];
+ [self setValueType:@"d"];
+ }
+ else if ([_type isEqualToString:@"decimal"]) {
+ [self setValueClassName:@"NSNumber"];
+ [self setValueType:@"d"];
+ }
+ else if ([_type isEqualToString:@"numeric"]) {
+ [self setValueClassName:@"NSNumber"];
+ [self setValueType:@"d"];
+ }
+ else if ([_type isEqualToString:@"name"]) {
+ [self setExternalType:@"name"];
+ [self setValueClassName:@"NSString"];
+ }
+ else if ([_type isEqualToString:@"varchar"]) {
+ [self setExternalType:@"varchar"];
+ [self setValueClassName:@"NSString"];
+ }
+ else if ([_type isEqualToString:@"char"]) {
+ [self setExternalType:@"char"];
+ [self setValueClassName:@"NSString"];
+ }
+ else if ([_type isEqualToString:@"timestamp"]) {
+ [self setValueClassName:@"NSCalendarDate"];
+ [self setCalendarFormat:SQLITE3_TIMESTAMP_FORMAT];
+ }
+ else if ([_type isEqualToString:@"timestamptz"]) {
+ [self setValueClassName:@"NSCalendarDate"];
+ [self setCalendarFormat:SQLITE3_TIMESTAMP_FORMAT];
+ }
+ else if ([_type isEqualToString:@"datetime"]) {
+ [self setValueClassName:@"NSCalendarDate"];
+ [self setCalendarFormat:SQLITE3_DATETIME_FORMAT];
+ }
+ else if ([_type isEqualToString:@"date"]) {
+ [self setValueClassName:@"NSString"];
+ }
+ else if ([_type isEqualToString:@"time"]) {
+ [self setValueClassName:@"NSString"];
+ }
+ else if ([_type isEqualToString:@"text"]) {
+ [self setValueClassName:@"NSString"];
+ }
+ else {
+ NSLog(@"invalid argument %@", _type);
+
+ [NSException raise:@"InvalidArgumentException"
+ format:@"invalid SQLite type %@ passed to %s",
+ _type, __PRETTY_FUNCTION__];
+ }
+}
+
+@end /* EOAttribute(SQLite) */
+
+void __link_EOAttributeSQLite() {
+ // used to force linking of object file
+ __link_EOAttributeSQLite();
+}
--- /dev/null
+#
+# GNUmakefile
+#
+# Copyright (C) 2005 Helge Hess
+#
+# Author: Helge Hess (helge.hess@opengroupware.org)
+#
+# This file is part of the SQLite Adaptor 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; see the file COPYING.LIB.
+# If not, write to the Free Software Foundation,
+# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+include $(GNUSTEP_MAKEFILES)/common.make
+
+BUNDLE_NAME = SQLite3
+
+SQLite3_OBJC_FILES = \
+ SQLiteExpression.m \
+ SQLiteAdaptor.m \
+ SQLiteContext.m \
+ SQLiteChannel.m \
+ SQLiteChannel+Model.m \
+ SQLiteException.m \
+ SQLiteValues.m \
+ NSString+SQLite.m \
+ EOAttribute+SQLite.m \
+ NSString+SQLiteVal.m \
+ NSData+SQLiteVal.m \
+ NSCalendarDate+SQLiteVal.m \
+ NSNumber+SQLiteVal.m \
+
+SQLite3_PRINCIPAL_CLASS = SQLiteAdaptor
+
+BUNDLE_INSTALL = SQLite3
+BUNDLE_INSTALL_DIR = $(GNUSTEP_SYSTEM_ROOT)/Libraries/Adaptors
+
+# Use .gdladaptor as the bundle extension
+BUNDLE_EXTENSION = .gdladaptor
+
+SQLite3_RESOURCE_FILES += Version
+
+# tool
+
+TOOL_NAME = gdltest
+
+gdltest_OBJC_FILES = gdltest.m
+
+-include GNUmakefile.preamble
+include $(GNUSTEP_MAKEFILES)/bundle.make
+#include $(GNUSTEP_MAKEFILES)/tool.make
+-include GNUmakefile.postamble
--- /dev/null
+#
+# GNUmakefile
+#
+# Copyright (C) 2003-2005 Helge Hess
+#
+# Author: Helge Hess (helge.hess@opengroupware.org)
+#
+# This file is part of the SQLite3 Adaptor 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; see the file COPYING.LIB.
+# If not, write to the Free Software Foundation,
+# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+SQLite3_BUNDLE_LIBS += -lsqlite3
+
+gdltest_TOOL_LIBS += -lGDLAccess
+
+# set compile flags and go
+
+ADDITIONAL_INCLUDE_DIRS += \
+ -I.. -I../.. \
+ -I/usr/local/include \
+ -I/usr/include \
+
+ADDITIONAL_LIB_DIRS += \
+ -L../$(GNUSTEP_OBJ_DIR) \
+ -L/usr/local/lib \
+ -L/usr/lib \
+
--- /dev/null
+// $Id: NSCalendarDate+SQLiteVal.m,v 1.1 2004/06/14 14:27:44 helge Exp $
+
+#import <Foundation/NSString.h>
+#include "SQLiteChannel.h"
+#include "common.h"
+
+static NSString *SQLITE3_DATETIME_FORMAT = @"%b %d %Y %I:%M:%S:000%p";
+
+@implementation NSCalendarDate(SQLiteValues)
+
+/*
+ Format: '2001-07-26 14:00:00+02'
+ '2001-07-26 14:00:00+09:30'
+ 0123456789012345678901234
+
+ Matthew: "07/25/2003 06:00:00 CDT".
+*/
+
+static Class NSCalDateClass = Nil;
+static NSTimeZone *DefServerTimezone = nil;
+static NSTimeZone *gmt = nil;
+static NSTimeZone *gmt01 = nil;
+static NSTimeZone *gmt02 = nil;
+
++ (id)valueFromCString:(const char *)_cstr length:(int)_length
+ sqlite3Type:(NSString *)_type
+ attribute:(EOAttribute *)_attribute
+ adaptorChannel:(SQLiteChannel *)_channel
+{
+ static unsigned char buf[28]; // reused buffer
+ unsigned char *p;
+ NSTimeZone *attrTZ;
+ NSCalendarDate *date;
+ int year, month, day, hour, min, sec, tzOffset;
+
+ if (_length == 0)
+ return nil;
+
+ if (_length != 22 && _length != 25) {
+ NSLog(@"ERROR(%s): unexpected string '%s' for date type '%@', returning now"
+ @" (expected format: '2001-07-26 14:00:00+02')",
+ __PRETTY_FUNCTION__,
+ _cstr, _type);
+ return [NSCalendarDate date];
+ }
+ strncpy(buf, _cstr, 25);
+ buf[25] = '\0';
+
+ /* perform on reverse, so that we don't overwrite with null-terminators */
+
+ if (_length == 22) {
+ p = &(buf[19]);
+ tzOffset = atoi(p) * 60;
+ }
+ else if (_length >= 25) {
+ int mins;
+ p = &(buf[23]);
+ mins = atoi(p);
+ buf[22] = '\0'; // the ':'
+ p = &(buf[19]);
+ tzOffset = atoi(p) * 60;
+ tzOffset = tzOffset > 0 ? (tzOffset + mins) : (tzOffset - mins);
+ }
+
+ p = &(buf[17]); buf[19] = '\0'; sec = atoi(p);
+ p = &(buf[14]); buf[16] = '\0'; min = atoi(p);
+ p = &(buf[11]); buf[13] = '\0'; hour = atoi(p);
+ p = &(buf[8]); buf[10] = '\0'; day = atoi(p);
+ p = &(buf[5]); buf[7] = '\0'; month = atoi(p);
+ p = &(buf[0]); buf[4] = '\0'; year = atoi(p);
+
+ /* TODO: cache all timezones (just 26 ;-) */
+ switch (tzOffset) {
+ case 0:
+ if (gmt == nil) {
+ gmt = [[NSTimeZone timeZoneForSecondsFromGMT:0] retain];
+ NSAssert(gmt, @"could not create GMT timezone?!");
+ }
+ attrTZ = gmt;
+ break;
+ case 60:
+ if (gmt01 == nil) {
+ gmt01 = [[NSTimeZone timeZoneForSecondsFromGMT:3600] retain];
+ NSAssert(gmt01, @"could not create GMT+01 timezone?!");
+ }
+ attrTZ = gmt01;
+ break;
+ case 120:
+ if (gmt02 == nil) {
+ gmt02 = [[NSTimeZone timeZoneForSecondsFromGMT:7200] retain];
+ NSAssert(gmt02, @"could not create GMT+02 timezone?!");
+ }
+ attrTZ = gmt02;
+ break;
+
+ default: {
+ /* cache the first, "alternative" timezone */
+ static int firstTZOffset = 0; // can use 0 since GMT is a separate case
+ static NSTimeZone *firstTZ = nil;
+ if (firstTZOffset == 0) {
+ firstTZOffset = tzOffset;
+ firstTZ = [[NSTimeZone timeZoneForSecondsFromGMT:(tzOffset*60)] retain];
+ }
+
+ attrTZ = (firstTZOffset == tzOffset)
+ ? firstTZ
+ : [NSTimeZone timeZoneForSecondsFromGMT:(tzOffset * 60)];
+ break;
+ }
+ }
+
+ if (NSCalDateClass == Nil) NSCalDateClass = [[NSCalendarDate class] retain];
+ date = [NSCalDateClass dateWithYear:year month:month day:day
+ hour:hour minute:min second:sec
+ timeZone:attrTZ];
+ if (date == nil) {
+ NSLog(@"ERROR(%s): could not construct date from string '%s': "
+ @"year=%i,month=%i,day=%i,hour=%i,minute=%i,second=%i, tz=%@",
+ __PRETTY_FUNCTION__, _cstr,
+ year, month, day, hour, min, sec, attrTZ);
+ }
+ return date;
+}
+
++ (id)valueFromBytes:(const void *)_bytes length:(int)_length
+ sqlite3Type:(NSString *)_type
+ attribute:(EOAttribute *)_attribute
+ adaptorChannel:(SQLiteChannel *)_channel
+{
+ return [self notImplemented:_cmd];
+}
+
+- (NSString *)stringValueForSQLite3Type:(NSString *)_type
+ attribute:(EOAttribute *)_attribute
+{
+#if 0
+ NSString *format;
+#endif
+ EOQuotedExpression *expr;
+ NSTimeZone *serverTimeZone;
+ NSString *format;
+ NSString *val;
+
+ if ((serverTimeZone = [_attribute serverTimeZone]) == nil ) {
+ if (DefServerTimezone == nil) {
+ DefServerTimezone = [[NSTimeZone localTimeZone] retain];
+ NSLog(@"Note: SQLite adaptor using timezone '%@' as default",
+ DefServerTimezone);
+ }
+ serverTimeZone = DefServerTimezone;
+ }
+
+#if 0
+ format = [_attribute calendarFormat];
+#else /* hm, why is that? */
+ format = @"%Y-%m-%d %H:%M:%S%z";
+#endif
+ if (format == nil)
+ format = SQLITE3_DATETIME_FORMAT;
+
+ [self setTimeZone:serverTimeZone];
+
+ val = [self descriptionWithCalendarFormat:format];
+ expr = [[EOQuotedExpression alloc] initWithExpression:val
+ quote:@"\'" escape:@"\\'"];
+ val = [[expr expressionValueForContext:nil] retain];
+ [expr release];
+
+ return [val autorelease];
+}
+
+@end /* NSCalendarDate(SQLiteValues) */
--- /dev/null
+/*
+ SQLiteAdaptor.h
+
+ Copyright (C) 2003-2005 SKYRIX Software AG
+
+ Author: Helge Hess (helge.hess@skyrix.com)
+
+ This file is part of the SQLite Adaptor 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; see the file COPYING.LIB.
+ If not, write to the Free Software Foundation,
+ 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+
+#include "SQLiteValues.h"
+#include "SQLiteChannel.h"
+#import <Foundation/NSData.h>
+#include "common.h"
+
+@implementation NSData(SQLiteValues)
+
+static NSData *EmptyData = nil;
+
++ (id)valueFromCString:(const char *)_cstr length:(int)_length
+ sqlite3Type:(NSString *)_type
+ attribute:(EOAttribute *)_attribute
+ adaptorChannel:(SQLiteChannel *)_channel
+{
+ if (_length == 0) {
+ if (EmptyData == nil) EmptyData = [[NSData alloc] init];
+ return EmptyData;
+ }
+ return [[[self alloc] initWithBytes:_cstr length:_length] autorelease];
+}
+
++ (id)valueFromBytes:(const void *)_bytes length:(int)_length
+ sqlite3Type:(NSString *)_type
+ attribute:(EOAttribute *)_attribute
+ adaptorChannel:(SQLiteChannel *)_channel
+{
+ if (_length == 0) {
+ if (EmptyData == nil) EmptyData = [[NSData alloc] init];
+ return EmptyData;
+ }
+ return [[[self alloc] initWithBytes:_bytes length:_length] autorelease];
+}
+
+- (NSString *)stringValueForSQLite3Type:(NSString *)_type
+ attribute:(EOAttribute *)_attribute
+{
+ // TODO: UNICODE
+ // TODO: this method looks slow
+ static NSStringEncoding enc = 0;
+ NSString *str, *t;
+ unsigned len;
+ unichar c1;
+
+ if ((len = [self length]) == 0)
+ return @"";
+
+ if (enc == 0) {
+ enc = [NSString defaultCStringEncoding];
+ NSLog(@"Note: SQLite adaptor using '%@' encoding for data=>string "
+ @"conversion.",
+ [NSString localizedNameOfStringEncoding:enc]);
+ }
+
+ str = [[NSString alloc] initWithData:self encoding:enc];
+
+ if (((len = [_type length]) == 0) || (len != 4 && len != 5 && len != 7))
+ return [str autorelease];
+
+ c1 = [_type characterAtIndex:0];
+ switch (c1) {
+ case 'c': case 'C':
+ case 'v': case 'V':
+ case 'm': case 'M':
+ case 't': case 'T':
+ t = [_type lowercaseString];
+ if ([t hasPrefix:@"char"] ||
+ [t hasPrefix:@"varchar"] ||
+ [t hasPrefix:@"money"] ||
+ [t hasPrefix:@"text"]) {
+ t = [[str stringValueForSQLite3Type:_type
+ attribute:_attribute] retain];
+ [str release];
+ return [t autorelease];
+ }
+ }
+
+ return [str autorelease];;
+}
+
+@end /* NSData(SQLiteValues) */
--- /dev/null
+/*
+ SQLiteAdaptor.h
+
+ Copyright (C) 2003-2005 SKYRIX Software AG
+
+ Author: Helge Hess (helge.hess@skyrix.com)
+
+ This file is part of the SQLite Adaptor 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; see the file COPYING.LIB.
+ If not, write to the Free Software Foundation,
+ 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+
+#import <Foundation/NSString.h>
+#include "SQLiteChannel.h"
+#include "common.h"
+
+@implementation NSNumber(SQLiteValues)
+
+static Class NSNumberClass = Nil;
+static NSNumber *yesNum = nil;
+static NSNumber *noNum = nil;
+
++ (id)valueFromCString:(const char *)_cstr length:(int)_length
+ sqlite3Type:(NSString *)_type
+ attribute:(EOAttribute *)_attribute
+ adaptorChannel:(SQLiteChannel *)_channel
+{
+ // TODO: can we avoid the lowercaseString?
+ unsigned len;
+ unichar c1;
+
+ if ((len = [_type length]) == 0)
+ return nil;
+
+ if (NSNumberClass == Nil) NSNumberClass = [NSNumber class];
+
+ c1 = [_type characterAtIndex:0];
+ switch (c1) {
+ case 'f': case 'F': {
+ if (len < 5)
+ break;
+ if ([[_type lowercaseString] hasPrefix:@"float"])
+ return [NSNumberClass numberWithDouble:atof(_cstr)];
+ break;
+ }
+ case 's': case 'S': {
+ if (len < 8)
+ break;
+ if ([[_type lowercaseString] hasPrefix:@"smallint"])
+ return [NSNumberClass numberWithShort:atoi(_cstr)];
+ break;
+ }
+ case 'i': case 'I': {
+ if (len < 3)
+ break;
+ if ([[_type lowercaseString] hasPrefix:@"int"])
+ return [NSNumberClass numberWithInt:atoi(_cstr)];
+ }
+ case 'b': case 'B': {
+ if (len < 4)
+ break;
+ if (![[_type lowercaseString] hasPrefix:@"bool"])
+ break;
+
+ if (yesNum == nil) yesNum = [[NSNumberClass numberWithBool:YES] retain];
+ if (noNum == nil) noNum = [[NSNumberClass numberWithBool:NO] retain];
+
+ if (_length == 0)
+ return noNum;
+
+ switch (*_cstr) {
+ case 't': case 'T':
+ case 'y': case 'Y':
+ case '1':
+ return yesNum;
+ default:
+ return noNum;
+ }
+ }
+ }
+ return nil;
+}
+
++ (id)valueFromBytes:(const void *)_bytes length:(int)_length
+ sqlite3Type:(NSString *)_type
+ attribute:(EOAttribute *)_attribute
+ adaptorChannel:(SQLiteChannel *)_channel
+{
+ return [self notImplemented:_cmd];
+}
+
+- (NSString *)stringValueForSQLite3Type:(NSString *)_type
+ attribute:(EOAttribute *)_attribute
+{
+ // TODO: can we avoid the lowercaseString?
+ unsigned len;
+ unichar c1;
+
+ if ((len = [_type length]) == 0)
+ return [self stringValue];
+ if (len < 4)
+ return [self stringValue];
+
+ c1 = [_type characterAtIndex:0];
+ switch (c1) {
+ case 'b': case 'B':
+ if (![[_type lowercaseString] hasPrefix:@"bool"])
+ break;
+ return [self boolValue] ? @"true" : @"false";
+
+ case 'm': case 'M': {
+ if (![[_type lowercaseString] hasPrefix:@"money"])
+ break;
+ return [@"$" stringByAppendingString:[self stringValue]];
+ }
+
+ case 'c': case 'C':
+ case 't': case 'T':
+ case 'v': case 'V': {
+ static NSMutableString *ms = nil; // reuse mstring, THREAD
+
+ _type = [_type lowercaseString];
+ if (!([_type hasPrefix:@"char"] ||
+ [_type hasPrefix:@"varchar"] ||
+ [_type hasPrefix:@"text"]))
+ break;
+
+ // TODO: can we get this faster?!
+ if (ms == nil) ms = [[NSMutableString alloc] initWithCapacity:256];
+ [ms setString:@"'"];
+ [ms appendString:[self stringValue]];
+ [ms appendString:@"'"];
+ return [[ms copy] autorelease];
+ }
+ }
+ return [self stringValue];
+}
+
+@end /* NSNumber(SQLiteValues) */
--- /dev/null
+/*
+ NSString+SQLite.h
+
+ Copyright (C) 1999 MDlink online service center GmbH and Helge Hess
+
+ Author: Helge Hess (helge@mdlink.de)
+
+ This file is part of the SQLite Adaptor 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; see the file COPYING.LIB.
+ If not, write to the Free Software Foundation,
+ 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+// $Id: NSString+SQLite.h,v 1.1 2004/06/14 14:27:44 helge Exp $
+
+#ifndef ___SQLite_NSString_H___
+#define ___SQLite_NSString_H___
+
+#import <Foundation/NSString.h>
+
+@interface NSString(SQLiteMiscStrings)
+
+- (NSString *)_pgModelMakeInstanceVarName;
+- (NSString *)_pgModelMakeClassName;
+- (NSString *)_pgStringWithCapitalizedFirstChar;
+- (NSString *)_pgStripEndSpaces;
+
+@end
+
+#endif
--- /dev/null
+/*
+ NSString+SQLite.m
+
+ Copyright (C) 1999 MDlink online service center GmbH and Helge Hess
+
+ Author: Helge Hess (helge@mdlink.de)
+
+ This file is part of the SQLite Adaptor 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; see the file COPYING.LIB.
+ If not, write to the Free Software Foundation,
+ 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+// $Id: NSString+SQLite.m,v 1.1 2004/06/14 14:27:44 helge Exp $
+
+#if LIB_FOUNDATION_BOEHM_GC
+# include <objc/gc.h>
+#endif
+
+#import <objc/objc-api.h>
+#include "common.h"
+#import "NSString+SQLite.h"
+
+@implementation NSString(SQLiteMiscStrings)
+
+- (NSString *)_pgModelMakeInstanceVarName {
+ if ([self length] == 0)
+ return @"";
+ else {
+ unsigned clen = 0;
+ char *s = NULL;
+ int cnt, cnt2;
+
+ clen = [self cStringLength];
+ s = malloc(clen + 10);
+
+ [self getCString:s maxLength:clen];
+
+ for (cnt = cnt2 = 0; cnt < clen; cnt++, cnt2++) {
+ if ((s[cnt] == '_') && (s[cnt + 1] != '\0')) {
+ s[cnt2] = toupper(s[cnt + 1]);
+ cnt++;
+ }
+ else if ((s[cnt] == '2') && (s[cnt + 1] != '\0')) {
+ s[cnt2] = s[cnt];
+ cnt++;
+ cnt2++;
+ s[cnt2] = toupper(s[cnt]);
+ }
+ else
+ s[cnt2] = tolower(s[cnt]);
+ }
+ s[cnt2] = '\0';
+
+ return [[[NSString alloc]
+ initWithCStringNoCopy:s length:strlen(s) freeWhenDone:YES]
+ autorelease];
+ }
+}
+
+- (NSString *)_pgModelMakeClassName {
+ if ([self length] == 0)
+ return @"";
+ else {
+ unsigned clen = 0;
+ char *s = NULL;
+ int cnt, cnt2;
+
+ clen = [self cStringLength];
+ s = malloc(clen + 10);
+
+ [self getCString:s maxLength:clen];
+
+ for (cnt = cnt2 = 0; cnt < clen; cnt++, cnt2++) {
+ if ((s[cnt] == '_') && (s[cnt + 1] != '\0')) {
+ s[cnt2] = toupper(s[cnt + 1]);
+ cnt++;
+ }
+ else if ((s[cnt] == '2') && (s[cnt + 1] != '\0')) {
+ s[cnt2] = s[cnt];
+ cnt++;
+ cnt2++;
+ s[cnt2] = toupper(s[cnt]);
+ }
+ else
+ s[cnt2] = tolower(s[cnt]);
+ }
+ s[cnt2] = '\0';
+
+ s[0] = toupper(s[0]);
+
+ return [[[NSString alloc]
+ initWithCStringNoCopy:s length:strlen(s)
+ freeWhenDone:YES]
+ autorelease];
+ }
+}
+
+- (NSString *)_pgStringWithCapitalizedFirstChar {
+ NSCharacterSet *upperSet = [NSCharacterSet uppercaseLetterCharacterSet];
+
+ if ([self length] == 0)
+ return @"";
+ else if ([upperSet characterIsMember:[self characterAtIndex:0]])
+ return [[self copy] autorelease];
+ else {
+ NSMutableString *str = [NSMutableString stringWithCapacity:[self length]];
+
+ [str appendString:[[self substringToIndex:1] uppercaseString]];
+ [str appendString:[self substringFromIndex:1]];
+
+ return [[str copy] autorelease];
+ }
+}
+
+- (NSString *)_pgStripEndSpaces {
+ if ([self length] > 0) {
+ NSCharacterSet *spaceSet = [NSCharacterSet whitespaceCharacterSet];
+ NSMutableString *str = [NSMutableString stringWithCapacity:[self length]];
+ IMP charAtIndex;
+ NSRange range;
+
+ charAtIndex = [self methodForSelector:@selector(characterAtIndex:)];
+ range.length = 0;
+
+ for (range.location = ([self length] - 1);
+ range.location >= 0;
+ range.location++, range.length++) {
+ unichar c;
+
+ c = (unichar)(int)charAtIndex(self, @selector(characterAtIndex:),
+ range.location);
+ if (![spaceSet characterIsMember:c])
+ break;
+ }
+
+ if (range.length > 0) {
+ [str appendString:self];
+ [str deleteCharactersInRange:range];
+ return AUTORELEASE([str copy]);
+ }
+ }
+ return AUTORELEASE([self copy]);
+}
+
+@end
+
+void __link_NSStringSQLite() {
+ // used to force linking of object file
+ __link_NSStringSQLite();
+}
--- /dev/null
+/*
+ SQLiteAdaptor.h
+
+ Copyright (C) 2003-2005 SKYRIX Software AG
+
+ Author: Helge Hess (helge.hess@skyrix.com)
+
+ This file is part of the SQLite Adaptor 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; see the file COPYING.LIB.
+ If not, write to the Free Software Foundation,
+ 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+
+#include "SQLiteChannel.h"
+#import <Foundation/NSString.h>
+#include "common.h"
+
+@implementation NSString(SQLiteValues)
+
+static Class NSStringClass = Nil;
+static Class EOExprClass = Nil;
+
++ (id)valueFromCString:(const char *)_cstr length:(int)_length
+ sqlite3Type:(NSString *)_type
+ attribute:(EOAttribute *)_attribute
+ adaptorChannel:(SQLiteChannel *)_channel
+{
+ if (_cstr == NULL) return nil;
+ if (*_cstr == '\0') return @"";
+ if (NSStringClass == Nil) NSStringClass = [NSString class];
+
+ // TODO: cache IMP of selector
+ return [NSStringClass stringWithCString:_cstr];
+}
+
++ (id)valueFromBytes:(const void *)_bytes length:(int)_length
+ sqlite3Type:(NSString *)_type
+ attribute:(EOAttribute *)_attribute
+ adaptorChannel:(SQLiteChannel *)_channel
+{
+ return [self notImplemented:_cmd];
+}
+
+- (NSString *)stringValueForSQLite3Type:(NSString *)_type
+ attribute:(EOAttribute *)_attribute
+{
+ // TODO: all this looks slow ...
+ unsigned len;
+ unichar c1;
+
+ if ((len = [_type length]) == 0)
+ return self;
+
+ c1 = [_type characterAtIndex:0];
+ switch (c1) {
+ case 'c': case 'C':
+ case 'v': case 'V':
+ case 't': case 'T': {
+ NSString *s;
+ id expr;
+
+ if (len < 4)
+ return self;
+
+ _type = [_type lowercaseString];
+
+ if (!([_type hasPrefix:@"char"] ||
+ [_type hasPrefix:@"varchar"] ||
+ [_type hasPrefix:@"text"]))
+ break;
+
+ /* TODO: creates too many autoreleased strings :-( */
+
+ expr = [self stringByReplacingString:@"\\" withString:@"\\\\"];
+
+ if (EOExprClass == Nil) EOExprClass = [EOQuotedExpression class];
+ expr = [[EOExprClass alloc] initWithExpression:expr
+ quote:@"'" escape:@"\\'"];
+ s = [[expr expressionValueForContext:nil] retain];
+ [expr release];
+ return [s autorelease];
+ }
+ case 'm': case 'M': {
+ if (len < 5) {
+ if ([[_type lowercaseString] hasPrefix:@"money"])
+ return [@"$" stringByAppendingString:self];
+ }
+ break;
+ }
+ }
+ return self;
+}
+
+@end /* NSString(SQLiteValues) */
--- /dev/null
+# SQLite3 Adaptor
+
+Note: this is far from being complete! The adaptor is currently a fork of
+ the PostgreSQL adaptor.
+
+TODO
+====
+- rename methods with 'pg' in the name
+- check EOAttribute+SQLite:
+ -loadValueClassAndTypeUsingSQLiteType:...
+- SQLiteChannel.m:
+ -primaryFetchAttributes => check field name processing
+
+Basics
+======
+
+Open a Shell:
+
+ sqlite3 OGo
+ > insert schema
+ > select * from date_x;
+
+Configure the Adaptor (below does not work yet for SQLite3!)
+
+ Defaults write ogo-webui-1.0a LSAdaptor SQLite3
+
+ Defaults write ogo-webui-1.0a LSConnectionDictionary \
+ '{ databaseName = OGo; }'
+
+ Defaults write ogo-webui-1.0a PKeyGeneratorDictionary \
+ "{ newKeyExpression=\"select nextval(\\'key_generator\\');\" }"
+
+ SQLiteDebugEnabled
+
+
+
+Sequential execution
+====================
+http://www.hwaci.com/sw/sqlite/c_interface.html
+
+---snip---
+typedef struct sqlite_vm sqlite_vm;
+
+int sqlite_compile(
+ sqlite *db, /* The open database */
+ const char *zSql, /* SQL statement to be compiled */
+ const char **pzTail, /* OUT: uncompiled tail of zSql */
+ sqlite_vm **ppVm, /* OUT: the virtual machine to execute zSql */
+ char **pzErrmsg /* OUT: Error message. */
+);
+
+int sqlite_step(
+ sqlite_vm *pVm, /* The virtual machine to execute */
+ int *pN, /* OUT: Number of columns in result */
+ const char ***pazValue, /* OUT: Column data */
+ const char ***pazColName /* OUT: Column names and datatypes */
+);
+
+int sqlite_finalize(
+ sqlite_vm *pVm, /* The virtual machine to be finalized */
+ char **pzErrMsg /* OUT: Error message */
+);
+---snap---
+
+
+Error-Codes
+===========
+
+---snip---
+#define SQLITE_OK 0 /* Successful result */
+#define SQLITE_ERROR 1 /* SQL error or missing database */
+#define SQLITE_INTERNAL 2 /* An internal logic error in SQLite */
+#define SQLITE_PERM 3 /* Access permission denied */
+#define SQLITE_ABORT 4 /* Callback routine requested an abort */
+#define SQLITE_BUSY 5 /* The database file is locked */
+#define SQLITE_LOCKED 6 /* A table in the database is locked */
+#define SQLITE_NOMEM 7 /* A malloc() failed */
+#define SQLITE_READONLY 8 /* Attempt to write a readonly database */
+#define SQLITE_INTERRUPT 9 /* Operation terminated by sqlite_interrupt() */
+#define SQLITE_IOERR 10 /* Some kind of disk I/O error occurred */
+#define SQLITE_CORRUPT 11 /* The database disk image is malformed */
+#define SQLITE_NOTFOUND 12 /* (Internal Only) Table or record not found */
+#define SQLITE_FULL 13 /* Insertion failed because database is full */
+#define SQLITE_CANTOPEN 14 /* Unable to open the database file */
+#define SQLITE_PROTOCOL 15 /* Database lock protocol error */
+#define SQLITE_EMPTY 16 /* (Internal Only) Database table is empty */
+#define SQLITE_SCHEMA 17 /* The database schema changed */
+#define SQLITE_TOOBIG 18 /* Too much data for one row of a table */
+#define SQLITE_CONSTRAINT 19 /* Abort due to contraint violation */
+#define SQLITE_MISMATCH 20 /* Data type mismatch */
+#define SQLITE_MISUSE 21 /* Library used incorrectly */
+#define SQLITE_NOLFS 22 /* Uses OS features not supported on host */
+#define SQLITE_AUTH 23 /* Authorization denied */
+#define SQLITE_ROW 100 /* sqlite_step() has another row ready */
+#define SQLITE_DONE 101 /* sqlite_step() has finished executing */
+---snap---
--- /dev/null
+/*
+ SQLiteAdaptor.h
+
+ Copyright (C) 2003-2005 SKYRIX Software AG
+
+ Author: Helge Hess (helge.hess@skyrix.com)
+
+ This file is part of the SQLite Adaptor 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; see the file COPYING.LIB.
+ If not, write to the Free Software Foundation,
+ 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+
+#ifndef ___SQLite_Adaptor_H___
+#define ___SQLite_Adaptor_H___
+
+/*
+ The SQLite adaptor.
+
+ The connection dictionary of this adaptor understands these keys:
+ databaseName
+
+ The adaptor is based on libsqlite.
+*/
+
+#import <Foundation/NSMapTable.h>
+#import <GDLAccess/EOAdaptor.h>
+#import <GDLAccess/EOAttribute.h>
+
+@class NSString, NSMutableDictionary;
+
+@interface SQLiteAdaptor : EOAdaptor
+{
+}
+
+- (id)initWithName:(NSString *)_name;
+
+// connection management
+
+- (NSString *)databaseName;
+- (NSString *)newKeyExpression;
+
+// sequence for primary key generation
+
+- (NSString *)primaryKeySequenceName;
+
+// value formatting
+
+- (id)formatValue:(id)value forAttribute:(EOAttribute *)attribute;
+
+// attribute typing
+
+- (BOOL)attributeAllowedInDistinctSelects:(EOAttribute *)_attr;
+
+// classes used
+
+- (Class)adaptorContextClass; // SQLiteContext
+- (Class)adaptorChannelClass; // SQLiteChannel
+- (Class)expressionClass; // SQLiteExpression
+
+@end
+
+#endif
--- /dev/null
+/*
+ SQLiteAdaptor.m
+
+ Copyright (C) 2003 SKYRIX Software AG
+
+ Author: Helge Hess (helge.hess@skyrix.com)
+
+ This file is part of the SQLite Adaptor 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; see the file COPYING.LIB.
+ If not, write to the Free Software Foundation,
+ 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+// $Id: SQLiteAdaptor.m,v 1.1 2004/06/14 14:27:44 helge Exp $
+
+#import "common.h"
+#import "SQLiteAdaptor.h"
+#import "SQLiteContext.h"
+#import "SQLiteChannel.h"
+#import "SQLiteExpression.h"
+#import "SQLiteValues.h"
+
+@implementation SQLiteAdaptor
+
+- (id)initWithName:(NSString *)_name {
+ if ((self = [super initWithName:_name])) {
+ }
+ return self;
+}
+
+/* NSCopying methods */
+
+- (id)copyWithZone:(NSZone *)_zone {
+ return [self retain];
+}
+
+// connections
+
+- (NSString *)serverName {
+ return @"localhost";
+}
+- (NSString *)loginName {
+ return @"no-login-required";
+}
+- (NSString *)loginPassword {
+ return @"no-pwd-required";
+}
+- (NSString *)databaseName {
+ return [[[[self connectionDictionary]
+ objectForKey:@"databaseName"] copy] autorelease];
+}
+
+- (NSString *)port {
+ return @"no-port-required";
+}
+- (NSString *)options {
+ return [[[[self connectionDictionary]
+ objectForKey:@"options"] copy] autorelease];
+}
+
+/* sequence for primary key generation */
+
+- (NSString *)primaryKeySequenceName {
+ NSString *seqName;
+
+ seqName =
+ [[self pkeyGeneratorDictionary] objectForKey:@"primaryKeySequenceName"];
+ return [[seqName copy] autorelease];
+}
+
+- (NSString *)newKeyExpression {
+ NSString *newKeyExpr;
+
+ newKeyExpr =
+ [[self pkeyGeneratorDictionary] objectForKey:@"newKeyExpression"];
+ return [[newKeyExpr copy] autorelease];
+}
+
+// formatting
+
+- (NSString *)charConvertExpressionForAttributeNamed:(NSString *)_attrName {
+ return _attrName;
+}
+
+- (id)formatValue:(id)value forAttribute:(EOAttribute *)attribute {
+ NSString *result;
+
+ result = [value stringValueForSQLite3Type:[attribute externalType]
+ attribute:attribute];
+
+ //NSLog(@"formatting value %@ result %@", value, result);
+ //NSLog(@" value class %@ attr %@ attr type %@",
+ // [value class], attribute, [attribute externalType]);
+
+ return result;
+}
+
+- (BOOL)attributeAllowedInDistinctSelects:(EOAttribute *)_attr {
+ return YES;
+}
+
+/* types */
+
+- (BOOL)isValidQualifierType:(NSString *)_typeName {
+ return YES;
+}
+
+/* adaptor info */
+
+- (Class)adaptorContextClass {
+ return [SQLiteContext class];
+}
+- (Class)adaptorChannelClass {
+ return [SQLiteChannel class];
+}
+
+- (Class)expressionClass {
+ return [SQLiteExpression class];
+}
+
+@end /* SQLiteAdaptor */
+
+void __linkSQLiteAdaptor(void) {
+ extern void __link_EOAttributeSQLite();
+ extern void __link_NSStringSQLite();
+ extern void __link_SQLiteChannelModel();
+ extern void __link_SQLiteValues();
+ ;
+ [SQLiteChannel class];
+ [SQLiteContext class];
+ [SQLiteException class];
+ [SQLiteExpression class];
+ __link_EOAttributeSQLite();
+ __link_NSStringSQLite();
+ //__link_SQLiteChannelModel();
+ __link_SQLiteValues();
+ __linkSQLiteAdaptor();
+}
--- /dev/null
+/*
+ SQLiteChannel+Model.h
+
+ Copyright (C) 2003-2005 SKYRIX Software AG
+
+ Author: Helge Hess (helge.hess@skyrix.com)
+
+ This file is part of the SQLite Adaptor 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; see the file COPYING.LIB.
+ If not, write to the Free Software Foundation,
+ 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+
+#ifndef ___SQLite_ModelFetching_H___
+#define ___SQLite_ModelFetching_H___
+
+#import "SQLiteChannel.h"
+
+@class NSArray;
+@class EOModel;
+
+@interface SQLiteChannel(ModelFetching)
+
+- (EOModel *)describeModelWithTableNames:(NSArray *)_tableNames;
+- (NSArray *)describeTableNames;
+
+@end
+
+#endif
--- /dev/null
+/*
+ SQLiteChannel+Model.m
+
+ Copyright (C) 2003 SKYRIX Software AG
+
+ Author: Helge Hess (helge.hess@skyrix.com)
+
+ This file is part of the SQLite Adaptor 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; see the file COPYING.LIB.
+ If not, write to the Free Software Foundation,
+ 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+// $Id: SQLiteChannel+Model.m,v 1.1 2004/06/14 14:27:44 helge Exp $
+
+#include "SQLiteChannel.h"
+#include "NSString+SQLite.h"
+#include "EOAttribute+SQLite.h"
+#import "common.h"
+
+@interface EORelationship(FixMe)
+- (void)addJoin:(id)_join;
+@end
+
+@implementation SQLiteChannel(ModelFetching)
+
+- (NSArray *)_attributesForTableName:(NSString *)_tableName {
+ NSMutableArray *attributes;
+ NSString *sqlExpr;
+ NSArray *resultDescription;
+ NSDictionary *row;
+
+ if (![_tableName length])
+ return nil;
+
+ if (!(attributes = [self->_attributesForTableName
+ objectForKey:_tableName])) {
+ sqlExpr =
+ @"SELECT a.attnum, a.attname, t.typname, a.attlen, a.attnotnull "
+ @"FROM pg_class c, pg_attribute a, pg_type t "
+ @"WHERE c.relname='%@' AND a.attnum>0 AND a.attrelid=c.oid AND a.atttypid=t.oid "
+ @"ORDER BY attnum;";
+ sqlExpr = [NSString stringWithFormat:sqlExpr, _tableName];
+
+ if (![self evaluateExpression:sqlExpr]) {
+ fprintf(stderr,
+ "Couldn`t evaluate column-describe '%s' on table '%s'\n",
+ [sqlExpr cString], [_tableName cString]);
+ return nil;
+ }
+
+ resultDescription = [self describeResults];
+ attributes = [NSMutableArray arrayWithCapacity:16];
+
+ while ((row = [self fetchAttributes:resultDescription withZone:NULL])) {
+ EOAttribute *attribute;
+ NSString *columnName = nil;
+ NSString *externalType = nil;
+ NSString *attrName = nil;
+
+ columnName = [[row objectForKey:@"attname"] stringValue];
+ attrName = [columnName _pgModelMakeInstanceVarName];
+ externalType = [[row objectForKey:@"typname"] stringValue];
+
+ attribute = [[EOAttribute alloc] init];
+ [attribute setColumnName:columnName];
+ [attribute setName:attrName];
+ [attribute setExternalType:externalType];
+ [attribute loadValueClassForExternalSQLiteType:externalType];
+ [attributes addObject:attribute];
+ RELEASE(attribute);
+ }
+ [self->_attributesForTableName setObject:attributes forKey:_tableName];
+ //NSLog(@"got attrs: %@", attributes);
+ }
+ return attributes;
+}
+
+- (NSArray *)_primaryKeysNamesForTableName:(NSString *)_tableName {
+ NSArray *pkNameForTableName = nil;
+
+ if ([_tableName length] == 0)
+ return nil;
+
+ NSLog(@"%s: not supported on SQLite!", __PRETTY_FUNCTION__);
+ return nil;
+}
+
+- (NSArray *)_foreignKeysForTableName:(NSString *)_tableName {
+ return nil;
+}
+
+- (EOModel *)describeModelWithTableNames:(NSArray *)_tableNames {
+ NSMutableArray *buildRelShips = [NSMutableArray arrayWithCapacity:64];
+ EOModel *model = AUTORELEASE([EOModel new]);
+ int cnt, tc = [_tableNames count];
+
+ for (cnt = 0; cnt < tc; cnt++) {
+ NSMutableDictionary *relNamesUsed =
+ AUTORELEASE([NSMutableDictionary new]);
+ NSMutableArray *classProperties =
+ AUTORELEASE([NSMutableArray new]);
+ NSMutableArray *primaryKeyAttributes =
+ AUTORELEASE([NSMutableArray new]);
+ NSString *tableName = [_tableNames objectAtIndex:cnt];
+ NSArray *attributes = [self _attributesForTableName:tableName];
+ NSArray *pkeys = [self _primaryKeysNamesForTableName:tableName];
+ NSArray *fkeys = [self _foreignKeysForTableName:tableName];
+ EOEntity *entity = AUTORELEASE([EOEntity new]);
+ int cnt2;
+ int ac = [attributes count];
+ int fkc = [fkeys count];
+
+ [entity setName:[tableName _pgModelMakeClassName]];
+ [entity setClassName:
+ [@"EO" stringByAppendingString:[tableName _pgModelMakeClassName]]];
+ [entity setExternalName:tableName];
+ [classProperties addObjectsFromArray:[entity classProperties]];
+ [primaryKeyAttributes addObjectsFromArray:[entity primaryKeyAttributes]];
+ [model addEntity:entity];
+
+ for (cnt2 = 0; cnt2 < ac; cnt2++) {
+ EOAttribute *attribute = [attributes objectAtIndex:cnt2];
+ NSString *columnName = [attribute columnName];
+
+ [entity addAttribute:attribute];
+ [classProperties addObject:attribute];
+
+ if ([pkeys containsObject:columnName])
+ [primaryKeyAttributes addObject:attribute];
+ }
+ [entity setClassProperties:classProperties];
+ [entity setPrimaryKeyAttributes:primaryKeyAttributes];
+
+ for (cnt2 = 0; cnt2 < fkc; cnt2++) {
+ NSDictionary *fkey = [fkeys objectAtIndex:cnt2];
+ NSMutableArray *classProperties =
+ AUTORELEASE([NSMutableArray new]);
+ NSString *sa = [fkey objectForKey:@"sourceAttr"];
+ NSString *da = [fkey objectForKey:@"targetAttr"];
+ NSString *dt = [fkey objectForKey:@"targetTable"];
+ EORelationship *rel =
+ AUTORELEASE([[EORelationship alloc] init]);
+ EOJoin *join =
+ AUTORELEASE([[EOJoin alloc] init]);
+ NSString *relName = nil;
+
+ if ([pkeys containsObject:sa])
+ relName = [@"to" stringByAppendingString:[dt _pgModelMakeClassName]];
+ else {
+ relName = [@"to" stringByAppendingString:
+ [[sa _pgModelMakeInstanceVarName]
+ _pgStringWithCapitalizedFirstChar]];
+ if ([relName hasSuffix:@"Id"]) {
+ int cLength = [relName cStringLength];
+
+ relName = [relName substringToIndex:cLength - 2];
+ }
+ }
+ if ([relNamesUsed objectForKey:relName]) {
+ int useCount = [[relNamesUsed objectForKey:relName] intValue];
+
+ [relNamesUsed setObject:[NSNumber numberWithInt:(useCount++)] forKey:relName];
+ relName = [NSString stringWithFormat:@"%s%d",
+ [relName cString], useCount];
+ }
+ else
+ [relNamesUsed setObject:[NSNumber numberWithInt:0] forKey:relName];
+
+ [rel setName:relName];
+ //[rel setDestinationEntity:(EOEntity *)[dt _pgModelMakeClassName]];
+ [rel setToMany:NO];
+
+ // TODO: EOJoin is removed, fix this ...
+ [(id)join setSourceAttribute:
+ (EOAttribute *)[sa _pgModelMakeInstanceVarName]];
+ [(id)join setDestinationAttribute:
+ (EOAttribute *)[da _pgModelMakeInstanceVarName]];
+ [rel addJoin:join];
+
+ [entity addRelationship:rel];
+ [classProperties addObjectsFromArray:[entity classProperties]];
+ [classProperties addObject:rel];
+ [entity setClassProperties:classProperties];
+ [buildRelShips addObject:rel];
+ }
+
+ [entity setAttributesUsedForLocking:[entity attributes]];
+ }
+
+ [buildRelShips makeObjectsPerformSelector:
+ @selector(replaceStringsWithObjects)];
+ /*
+ // make reverse relations
+ {
+ int cnt, rc = [buildRelShips count];
+
+ for (cnt = 0; cnt < rc; cnt++) {
+ EORelationship *rel = [buildRelShips objectAtIndex:cnt];
+ NSMutableArray *classProperties = [NSMutableArray new];
+ EORelationship *reverse = [rel reversedRelationShip];
+ EOEntity *entity = [rel destinationEntity];
+ NSArray *pkeys = [entity primaryKeyAttributes];
+ BOOL isToMany = [reverse isToMany];
+ EOAttribute *sa = [[[reverse joins] lastObject] sourceAttribute];
+ NSString *relName = nil;
+
+ if ([pkeys containsObject:sa]
+ || isToMany)
+ relName = [@"to" stringByAppendingString:
+ [(EOEntity *)[reverse destinationEntity] name]];
+ else {
+ relName = [@"to" stringByAppendingString:
+ [[[sa name] _pgModelMakeInstanceVarName]
+ _pgStringWithCapitalizedFirstChar]];
+ if ([relName hasSuffix:@"Id"]) {
+ int cLength = [relName cStringLength];
+
+ relName = [relName substringToIndex:cLength - 2];
+ }
+ }
+
+ if ([entity relationshipNamed:relName]) {
+ int cnt = 1;
+ NSString *numName;
+
+ numName = [NSString stringWithFormat:@"%s%d", [relName cString], cnt];
+ while ([entity relationshipNamed:numName]) {
+ cnt++;
+ numName = [NSString stringWithFormat:@"%s%d", [relName cString], cnt];
+ }
+
+ relName = numName;
+ }
+
+ [reverse setName:relName];
+
+ [entity addRelationship:reverse];
+
+ [classProperties addObjectsFromArray:[entity classProperties]];
+ [classProperties addObject:reverse];
+ [entity setClassProperties:classProperties];
+ }
+ }
+ */
+ [model setAdaptorName:@"SQLite"];
+ [model setAdaptorClassName:@"SQLiteAdaptor"];
+ [model setConnectionDictionary:
+ [[adaptorContext adaptor] connectionDictionary]];
+
+ return model;
+}
+
+- (NSArray *)describeTableNames {
+ NSMutableArray *tableNames = nil;
+ NSArray *resultDescription = nil;
+ NSString *attributeName = nil;
+ NSDictionary *row = nil;
+ NSString *selectExpression = nil;
+
+ selectExpression =
+ @"SELECT relname "
+ @"FROM pg_class "
+ @"WHERE (relkind='r') AND relname !~ '^pg_' AND relname !~ '^xinv[0-9]+' "
+ @"ORDER BY relname";
+
+ if (![self evaluateExpression:selectExpression]) {
+ fprintf(stderr, "Couldn`t evaluate table-describe expression '%s'\n",
+ [selectExpression cString]);
+ return nil;
+ }
+
+ resultDescription = [self describeResults];
+ attributeName = [(EOAttribute *)[resultDescription objectAtIndex:0] name];
+ tableNames = [NSMutableArray arrayWithCapacity:16];
+
+ while ((row = [self fetchAttributes:resultDescription withZone:NULL]))
+ [tableNames addObject:[row objectForKey:attributeName]];
+
+ return tableNames;
+}
+
+@end /* SQLiteChannel(ModelFetching) */
+
+void __link_SQLiteChannelModel() {
+ // used to force linking of object file
+ __link_SQLiteChannelModel();
+}
--- /dev/null
+/*
+ SQLiteChannel.h
+
+ Copyright (C) 2003-2005 Helge Hess
+
+ Author: Helge Hess (helge.hess@opengroupware.org)
+
+ This file is part of the SQLite Adaptor 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; see the file COPYING.LIB.
+ If not, write to the Free Software Foundation,
+ 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+
+#ifndef ___SQLite_Channel_H___
+#define ___SQLite_Channel_H___
+
+#import <GDLAccess/EOAdaptorChannel.h>
+#include <sqlite3.h>
+
+@class NSArray, NSString, NSMutableDictionary;
+
+@interface SQLiteChannel : EOAdaptorChannel
+{
+ // connection is valid after an openChannel call
+ void *_connection;
+
+ // valid during -evaluateExpression:
+ void *results;
+ int tupleCount;
+ int fieldCount;
+ BOOL containsBinaryData;
+ NSString *cmdStatus;
+ NSString *cmdTuples;
+ NSString *oidStatus;
+ int currentTuple;
+
+ // turns on/off channel debugging
+ BOOL isDebuggingEnabled;
+
+ NSMutableDictionary *_attributesForTableName;
+ NSMutableDictionary *_primaryKeysNamesForTableName;
+}
+
+- (void)setDebugEnabled:(BOOL)_flag;
+- (BOOL)isDebugEnabled;
+
+- (BOOL)isOpen;
+- (BOOL)openChannel;
+- (void)closeChannel;
+
+- (NSMutableDictionary *)primaryFetchAttributes:(NSArray *)_attributes
+ withZone:(NSZone *)_zone;
+
+- (BOOL)evaluateExpression:(NSString *)_expression;
+
+// cancelFetch is always called to terminate a fetch
+// (even by primaryFetchAttributes)
+// it frees all fetch-local variables
+- (void)cancelFetch;
+
+// uses dataFormat type information to create EOAttribute objects
+- (NSArray *)describeResults;
+
+@end
+
+@interface NSObject(Sybase10ChannelDelegate)
+
+- (NSArray*)sqlite3Channel:(SQLiteChannel *)channel
+ willFetchAttributes:(NSArray *)attributes;
+
+- (BOOL)sqlite3Channel:(SQLiteChannel *)channel
+ willReturnRow:(NSDictionary *)row;
+
+@end
+
+#endif /* ___SQLite_Channel_H___ */
--- /dev/null
+/*
+ SQLiteChannel.m
+
+ Copyright (C) 2003-2005 SKYRIX Software AG
+
+ Author: Helge Hess (helge.hess@skyrix.com)
+
+ This file is part of the SQLite Adaptor 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; see the file COPYING.LIB.
+ If not, write to the Free Software Foundation,
+ 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+
+#include <ctype.h>
+#include <string.h>
+#include <strings.h>
+#include "SQLiteChannel.h"
+#include "SQLiteAdaptor.h"
+#include "SQLiteException.h"
+#include "NSString+SQLite.h"
+#include "SQLiteValues.h"
+#include "EOAttribute+SQLite.h"
+#include "common.h"
+
+#ifndef MIN
+# define MIN(x, y) ((x > y) ? y : x)
+#endif
+
+#define MAX_CHAR_BUF 16384
+
+@implementation SQLiteChannel
+
+static EONull *null = nil;
+
++ (void)initialize {
+ if (null == NULL) null = [[EONull null] retain];
+}
+
+- (id)initWithAdaptorContext:(EOAdaptorContext*)_adaptorContext {
+ if ((self = [super initWithAdaptorContext:_adaptorContext])) {
+ [self setDebugEnabled:[[NSUserDefaults standardUserDefaults]
+ boolForKey:@"SQLiteDebugEnabled"]];
+ self->_attributesForTableName = [[NSMutableDictionary alloc]
+ initWithCapacity:16];
+ self->_primaryKeysNamesForTableName =
+ [[NSMutableDictionary alloc] initWithCapacity:16];
+ }
+ return self;
+}
+
+- (void)_adaptorWillFinalize:(id)_adaptor {
+}
+
+- (void)dealloc {
+ if ([self isOpen])
+ [self closeChannel];
+ [self->_attributesForTableName release];
+ [self->_primaryKeysNamesForTableName release];
+ [super dealloc];
+}
+
+/* NSCopying methods */
+
+- (id)copyWithZone:(NSZone *)zone {
+ return [self retain];
+}
+
+// debugging
+
+- (void)setDebugEnabled:(BOOL)_flag {
+ self->isDebuggingEnabled = _flag;
+}
+- (BOOL)isDebugEnabled {
+ return self->isDebuggingEnabled;
+}
+
+- (void)receivedMessage:(NSString *)_message {
+ NSLog(@"%@: message %@.", _message);
+}
+
+/* open/close */
+
+static int openConnectionCount = 0;
+
+- (BOOL)isOpen {
+ return (self->_connection != NULL) ? YES : NO;
+}
+
+- (BOOL)openChannel {
+ SQLiteAdaptor *adaptor;
+ int rc;
+
+ if (self->_connection) {
+ NSLog(@"%s: Connection already open !!!", __PRETTY_FUNCTION__);
+ return NO;
+ }
+
+ adaptor = (SQLiteAdaptor *)[adaptorContext adaptor];
+
+ if (![super openChannel])
+ return NO;
+
+#if 0
+ NSLog(@"+++++++++ %s: openConnectionCount %d", __PRETTY_FUNCTION__,
+ openConnectionCount);
+#endif
+ {
+ static int MaxOpenConnectionCount = -1;
+
+ if (MaxOpenConnectionCount == -1) {
+ MaxOpenConnectionCount =
+ [[NSUserDefaults standardUserDefaults]
+ integerForKey:@"SQLiteMaxOpenConnectionCount"];
+ if (MaxOpenConnectionCount == 0) {
+ MaxOpenConnectionCount = 15;
+ }
+ }
+ if (openConnectionCount > MaxOpenConnectionCount) {
+ [SQLiteCouldNotOpenChannelException raise:
+ @"NoMoreConnections"
+ format:
+ @"cannot open a additional connection !"];
+ return NO;
+ }
+ }
+
+ rc = sqlite3_open([[adaptor databaseName] UTF8String],
+ (void *)&(self->_connection));
+ if (rc != SQLITE_OK) {
+ // could not login ..
+ // Note: connection *is* set! (might be required to deallocate)
+ NSLog(@"WARNING: could not open SQLite connection to database '%@': %s",
+ [adaptor databaseName], sqlite3_errmsg(self->_connection));
+ sqlite3_close(self->_connection);
+ return NO;
+ }
+
+ if (isDebuggingEnabled)
+ NSLog(@"SQLite connection established 0x%08X", self->_connection);
+
+#if 0
+ NSLog(@"---------- %s: %@ opens channel count[%d]", __PRETTY_FUNCTION__,
+ self, openConnectionCount);
+#endif
+ openConnectionCount++;
+
+#if LIB_FOUNDATION_BOEHM_GC
+ [GarbageCollector registerForFinalizationObserver:self
+ selector:@selector(_adaptorWillFinalize:)
+ object:[[self adaptorContext] adaptor]];
+#endif
+
+ if (isDebuggingEnabled) {
+ NSLog(@"SQLite channel 0x%08X opened (connection=0x%08X)",
+ (unsigned)self, self->_connection);
+ }
+ return YES;
+}
+
+- (void)primaryCloseChannel {
+ self->tupleCount = 0;
+ self->fieldCount = 0;
+ self->containsBinaryData = NO;
+
+ if (self->results) {
+ free(self->results);
+ self->results = NO;
+ }
+
+ RELEASE(self->cmdStatus); self->cmdStatus = nil;
+ RELEASE(self->cmdTuples); self->cmdTuples = nil;
+ RELEASE(self->oidStatus); self->oidStatus = nil;
+
+ if (self->_connection != NULL) {
+ sqlite3_close(self->_connection);
+#if 0
+ NSLog(@"---------- %s: %@ close channel count[%d]", __PRETTY_FUNCTION__,
+ self, openConnectionCount);
+#endif
+ openConnectionCount--;
+
+ if (isDebuggingEnabled) {
+ fprintf(stderr,
+ "SQLite connection dropped 0x%08X (channel=0x%08X)\n",
+ (unsigned)self->_connection, (unsigned)self);
+ }
+ self->_connection = NULL;
+ }
+}
+
+- (void)closeChannel {
+ [super closeChannel];
+ [self primaryCloseChannel];
+}
+
+/* fetching rows */
+
+- (void)cancelFetch {
+ if (![self isOpen]) {
+ [SQLiteException raise:@"ChannelNotOpenException"
+ format:@"No fetch in progress, connection is not open"
+ @" (channel=%@)", self];
+ }
+
+#if 0
+ NSLog(@"canceling fetch (%i tuples remaining).",
+ (self->tupleCount - self->currentTuple));
+#endif
+
+ self->tupleCount = 0;
+ self->currentTuple = 0;
+ self->fieldCount = 0;
+ self->containsBinaryData = NO;
+
+ if (self->results) {
+ free(self->results);
+ self->results = NO;
+ }
+
+ RELEASE(self->cmdStatus); self->cmdStatus = nil;
+ RELEASE(self->cmdTuples); self->cmdTuples = nil;
+ RELEASE(self->oidStatus); self->oidStatus = nil;
+
+ [super cancelFetch];
+}
+
+- (NSArray *)describeResults {
+ int cnt;
+ NSMutableArray *result = nil;
+ NSMutableDictionary *usedNames = nil;
+ NSNumber *yesObj;
+
+ yesObj = [NSNumber numberWithBool:YES];
+
+ if (![self isFetchInProgress]) {
+ [SQLiteException raise:@"NoFetchInProgress"
+ format:@"No fetch in progress (channel=%@)", self];
+ }
+
+ result = [[NSMutableArray alloc] initWithCapacity:self->fieldCount];
+ usedNames = [[NSMutableDictionary alloc] initWithCapacity:self->fieldCount];
+
+ for (cnt = 0; cnt < self->fieldCount; cnt++) {
+ EOAttribute *attribute = nil;
+ NSString *columnName = nil;
+ NSString *attrName = nil;
+
+#if 1
+# warning TODO, columnName
+#else
+ columnName = [NSString stringWithCString:self->fieldInfo[cnt].name];
+#endif
+ attrName = [columnName _pgModelMakeInstanceVarName];
+
+ if ([[usedNames objectForKey:attrName] boolValue]) {
+ int cnt2 = 0;
+ char buf[64];
+ NSString *newAttrName = nil;
+
+ for (cnt2 = 2; cnt2 < 100; cnt2++) {
+ sprintf(buf, "%i", cnt2);
+
+ // TODO: unicode
+ newAttrName = [attrName stringByAppendingString:
+ [NSString stringWithCString:buf]];
+
+ if (![[usedNames objectForKey:newAttrName] boolValue]) {
+ attrName = newAttrName;
+ break;
+ }
+ }
+ }
+ [usedNames setObject:yesObj forKey:attrName];
+
+ attribute = [[EOAttribute alloc] init];
+ [attribute setName:attrName];
+ [attribute setColumnName:columnName];
+
+ //NSLog(@"column: %@", columnName);
+
+#if 1
+# warning TODO: loadValueClassAndTypeUsingSQLiteType:
+#else
+ [attribute loadValueClassAndTypeUsingSQLiteType:
+ self->fieldInfo[cnt].type
+ size:self->fieldInfo[cnt].size
+ modification:self->fieldInfo[cnt].modification
+ binary:self->containsBinaryData];
+#endif
+
+ [result addObject:attribute];
+
+ [attribute release];
+ }
+
+ [usedNames release];
+ usedNames = nil;
+
+ return [result autorelease];
+}
+
+- (NSMutableDictionary *)primaryFetchAttributes:(NSArray *)_attributes
+ withZone:(NSZone *)_zone
+{
+ NSMutableDictionary *row = nil;
+ unsigned attrCount = [_attributes count];
+ int indices[attrCount];
+ unsigned cnt;
+
+ if (self->currentTuple == self->tupleCount) {
+ if (self->results) [self cancelFetch];
+ return nil;
+ }
+ {
+#if 1
+# warning TODO: field name processing
+ NSMutableArray *fieldNames;
+ //unsigned nFields, i;
+
+ // TODO: we could probably cache the field-name array for much more speed !
+ fieldNames = [[NSMutableArray alloc] initWithCapacity:32];
+#else
+ nFields = PQnfields(self->results);
+ for (i = 0; i < nFields; i++) {
+ NSString *s;
+
+ s = [[NSString alloc] initWithCString:PQfname(self->results, i)];
+ [fieldNames addObject:s];
+ [s release];
+ }
+#endif
+
+ for (cnt = 0; cnt < attrCount; cnt++) {
+ EOAttribute *attribute = [_attributes objectAtIndex:cnt];
+
+ indices[cnt] = [fieldNames indexOfObject:[attribute columnName]];
+
+ if (indices[cnt] == NSNotFound) {
+ [SQLiteException raiseWithFormat:
+ @"attribute %@ not covered by query", attribute];
+ }
+ [fieldNames replaceObjectAtIndex:indices[cnt] withObject:[EONull null]];
+ }
+ [fieldNames release]; fieldNames = nil;
+ }
+
+
+ row = [NSMutableDictionary dictionaryWithCapacity:attrCount];
+
+ for (cnt = 0; cnt < attrCount; cnt++) {
+ EOAttribute *attribute;
+ NSString *attrName;
+ id value = nil;
+
+ attribute = [_attributes objectAtIndex:cnt];
+ attrName = [attribute name];
+
+#if 1
+# warning TODO: value creation
+#else
+ if (PQgetisnull(self->results, self->currentTuple, indices[cnt])) {
+ value = null;
+ }
+ else {
+ Class valueClass = Nil;
+ const char *pvalue;
+ int vallen;
+
+ valueClass = NSClassFromString([attribute valueClassName]);
+ if (valueClass == Nil) {
+ NSLog(@"ERROR(%s): %@: got no value class for column:\n"
+ @" attribute=%@\n type=%@",
+ __PRETTY_FUNCTION__, self,
+ attrName, [attribute externalType]);
+ value = null;
+ continue;
+ }
+
+ pvalue = PQgetvalue(self->results, self->currentTuple, indices[cnt]);
+ vallen = PQgetlength(self->results, self->currentTuple, indices[cnt]);
+
+ if (self->containsBinaryData) {
+ // pvalue is stored in internal representation
+
+ value = [valueClass valueFromBytes:pvalue length:vallen
+ sqlite3Type:[attribute externalType]
+ attribute:attribute
+ adaptorChannel:self];
+ }
+ else {
+ // pvalue is ASCII string
+
+ value = [valueClass valueFromCString:pvalue length:vallen
+ sqlite3Type:[attribute externalType]
+ attribute:attribute
+ adaptorChannel:self];
+ }
+ if (value == nil) {
+ NSLog(@"ERROR(%s): %@: got no value for column:\n"
+ @" attribute=%@\n valueClass=%@\n type=%@",
+ __PRETTY_FUNCTION__, self,
+ attrName, NSStringFromClass(valueClass),
+ [attribute externalType]);
+ continue;
+ }
+ }
+#endif
+
+ [row setObject:value forKey:attrName];
+ }
+
+ self->currentTuple++;
+
+ return row;
+}
+
+/* sending SQL to server */
+
+static int sqlite_result_callback
+(void *userdata, int columnCount, char **columns, char **columnNames)
+{
+ /* need to load into array ... */
+ SQLiteChannel *self = userdata;
+
+ NSLog(@"%@: SQLite callback, %i columns ...", self, columnCount);
+ return 0;
+}
+
+- (BOOL)evaluateExpression:(NSString *)_expression {
+ char *zErrMsg = NULL;
+ BOOL result;
+ int rc;
+
+ *(&result) = YES;
+
+ if (_expression == nil) {
+ [NSException raise:@"InvalidArgumentException"
+ format:@"parameter for evaluateExpression: "
+ @"must not be null (channel=%@)", self];
+ }
+
+ *(&_expression) = [[_expression mutableCopy] autorelease];
+
+ if (delegateRespondsTo.willEvaluateExpression) {
+ EODelegateResponse response;
+
+ response =
+ [delegate adaptorChannel:self
+ willEvaluateExpression:(NSMutableString *)_expression];
+
+ if (response == EODelegateRejects)
+ return NO;
+ if (response == EODelegateOverrides)
+ return YES;
+ }
+
+ if (![self isOpen]) {
+ [SQLiteException raise:@"ChannelNotOpenException"
+ format:@"SQLite connection is not open (channel=%@)",
+ self];
+ return NO;
+ }
+ if (self->results != NULL) {
+ [SQLiteException raise:@"CommandInProgressException"
+ format:@"an evaluation is in progress (channel=%@)",self];
+ return NO;
+ }
+
+ if (isDebuggingEnabled)
+ NSLog(@"%@ sql: %@", self, _expression);
+
+ self->isFetchInProgress = NO;
+ self->tupleCount = 0;
+ self->fieldCount = 0;
+ self->currentTuple = 0;
+ self->containsBinaryData = NO;
+
+ rc = sqlite3_exec(self->_connection,
+ [_expression UTF8String],
+ sqlite_result_callback,
+ self /* userdata */,
+ &zErrMsg);
+ if (rc != SQLITE_OK) {
+ NSString *err;
+
+ if (zErrMsg) {
+ err = [NSString stringWithCString:zErrMsg];
+ free(zErrMsg);
+ }
+ else
+ err = nil;
+
+ [SQLiteException raise:@"ExecutionFailed"
+ format:
+ @"the sqlite_exec(%@) call failed (channel=%@): %s",
+ _expression, self, err];
+ return NO;
+ }
+ if (zErrMsg) {
+ NSLog(@"WARNING(%@): pending error message: '%s'", self, zErrMsg);
+ free(zErrMsg);
+ }
+
+ /* only on empty results? */
+ if (delegateRespondsTo.didEvaluateExpression)
+ [delegate adaptorChannel:self didEvaluateExpression:_expression];
+
+ return NO;
+}
+
+/* description */
+
+- (NSString *)description {
+ NSMutableString *ms;
+
+ ms = [NSMutableString stringWithCapacity:64];
+ [ms appendFormat:@"<%@[0x%08X] connection=0x%08X",
+ NSStringFromClass([self class]),
+ self,
+ (unsigned)self->_connection];
+ [ms appendString:@">"];
+ return ms;
+}
+
+@end /* SQLiteChannel */
+
+@implementation SQLiteChannel(PrimaryKeyGeneration)
+
+- (NSDictionary *)primaryKeyForNewRowWithEntity:(EOEntity *)_entity {
+ NSArray *pkeys;
+ SQLiteAdaptor *adaptor;
+ NSString *seqName, *seq;
+ NSDictionary *pkey;
+
+ pkeys = [_entity primaryKeyAttributeNames];
+ adaptor = (id)[[self adaptorContext] adaptor];
+ seqName = [adaptor primaryKeySequenceName];
+ pkey = nil;
+ seq = nil;
+
+ if ([seqName length] > 0)
+ seq = [NSString stringWithFormat:@"SELECT NEXTVAL ('%@')", seqName];
+ else
+ seq = [adaptor newKeyExpression];
+
+ NS_DURING {
+ if ([self evaluateExpression:seq]) {
+ id key = nil;
+#if 0
+ if (self->tupleCount > 0) {
+ if (PQgetisnull(self->results, 0, 0))
+ key = null;
+ else {
+ const char *pvalue;
+ int vallen;
+
+ if (self->containsBinaryData) {
+ [self notImplemented:_cmd];
+ }
+
+ pvalue = PQgetvalue(self->results, 0, 0);
+ vallen = PQgetlength(self->results, 0, 0);
+
+ if (pvalue)
+ key = [NSNumber numberWithInt:atoi(pvalue)];
+ }
+ }
+#endif
+ // TODO
+ NSLog(@"%s: PKEY GEN NOT IMPLEMENTED!", __PRETTY_FUNCTION__);
+ [self cancelFetch];
+
+ if (key) {
+ pkey = [NSDictionary dictionaryWithObject:key
+ forKey:[pkeys objectAtIndex:0]];
+ }
+ }
+ }
+ NS_HANDLER {
+ pkey = nil;
+ }
+ NS_ENDHANDLER;
+
+ return pkey;
+}
+
+@end /* SQLiteChannel(PrimaryKeyGeneration) */
+
+void __link_SQLiteChannel() {
+ // used to force linking of object file
+ __link_SQLiteChannel();
+}
--- /dev/null
+/*
+ SQLiteContext.h
+
+ Copyright (C) 2003-2005 SKYRIX Software AG
+
+ Author: Helge Hess (helge.hess@skyrix.com)
+
+ This file is part of the SQLite Adaptor 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; see the file COPYING.LIB.
+ If not, write to the Free Software Foundation,
+ 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+
+#ifndef ___SQLite_Context_H___
+#define ___SQLite_Context_H___
+
+#import <GDLAccess/EOAdaptorContext.h>
+
+@interface SQLiteContext : EOAdaptorContext
+
+- (BOOL)primaryBeginTransaction;
+- (BOOL)primaryCommitTransaction;
+- (BOOL)primaryRollbackTransaction;
+
+@end
+
+#endif
--- /dev/null
+/*
+ SQLiteContext.m
+
+ Copyright (C) 2003-2005 SKYRIX Software AG
+
+ Author: Helge Hess (helge.hess@skyrix.com)
+
+ This file is part of the SQLite Adaptor 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; see the file COPYING.LIB.
+ If not, write to the Free Software Foundation,
+ 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+
+#include "SQLiteContext.h"
+#include "SQLiteChannel.h"
+#include "common.h"
+
+@implementation SQLiteContext
+
+- (void)channelDidInit:_channel {
+ if ([channels count] > 0) {
+ [NSException raise:@"TooManyOpenChannelsException"
+ format:@"SQLite3 only supports one channel per context"];
+ }
+ [super channelDidInit:_channel];
+}
+
+- (BOOL)primaryBeginTransaction {
+ BOOL result;
+
+ result = [[[channels lastObject]
+ nonretainedObjectValue]
+ evaluateExpression:@"BEGIN TRANSACTION"];
+
+ return result;
+}
+
+- (BOOL)primaryCommitTransaction {
+ BOOL result;
+
+ result = [[[channels lastObject]
+ nonretainedObjectValue]
+ evaluateExpression:@"COMMIT TRANSACTION"];
+
+ return result;
+}
+
+- (BOOL)primaryRollbackTransaction {
+ BOOL result;
+
+ result = [[[channels lastObject]
+ nonretainedObjectValue]
+ evaluateExpression:@"ROLLBACK TRANSACTION"];
+ return result;
+}
+
+- (BOOL)canNestTransactions {
+ return NO;
+}
+
+// NSCopying methods
+
+- (id)copyWithZone:(NSZone *)zone {
+ return [self retain];
+}
+
+@end /* SQLiteContext */
+
+void __link_SQLiteContext() {
+ // used to force linking of object file
+ __link_SQLiteContext();
+}
--- /dev/null
+/*
+ SQLiteException.h
+
+ Copyright (C) 1999-2005 MDlink online service center GmbH and Helge Hess
+
+ Author: Helge Hess (helge@mdlink.de)
+
+ This file is part of the SQLite Adaptor 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; see the file COPYING.LIB.
+ If not, write to the Free Software Foundation,
+ 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+
+#ifndef ___SQLite_Exception_H___
+#define ___SQLite_Exception_H___
+
+#import <Foundation/NSException.h>
+
+@interface SQLiteException : NSException
+{
+}
+
++ (void)raiseWithFormat:(NSString *)_format, ...;
+
+@end
+
+@interface SQLiteCouldNotOpenChannelException : SQLiteException
+{
+}
+@end
+
+@interface SQLiteCouldNotConnectException : SQLiteCouldNotOpenChannelException
+{
+}
+@end
+
+@interface SQLiteCouldNotBindException : SQLiteException
+{
+}
+@end
+
+#endif /* ___SQLite_Exception_H___ */
--- /dev/null
+/*
+ SQLiteException.m
+
+ Copyright (C) 2003-2005 Helge Hess
+
+ Author: Helge Hess (helge.hess@opengroupware.org)
+
+ This file is part of the SQLite Adaptor 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; see the file COPYING.LIB.
+ If not, write to the Free Software Foundation,
+ 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+
+#import <GDLAccess/GDLAccess.h>
+#import "SQLiteException.h"
+#include "common.h"
+
+@implementation SQLiteException
+
++ (void)raiseWithFormat:(NSString *)_format, ... {
+ NSString *tmp = nil;
+ va_list ap;
+
+ va_start(ap, _format);
+ tmp = [[NSString allocWithZone:[self zone]]
+ initWithFormat:_format arguments:ap];
+ va_end(ap);
+
+ AUTORELEASE(tmp);
+
+ [[[self alloc] initWithName:NSStringFromClass([self class])
+ reason:tmp userInfo:nil]
+ raise];
+}
+
+@end
+
+@implementation SQLiteCouldNotOpenChannelException
+@end
+
+@implementation SQLiteCouldNotConnectException
+@end
+
+@implementation SQLiteCouldNotBindException
+@end
+
+void __link_SQLiteException() {
+ // used to force linking of object file
+ __link_SQLiteException();
+}
--- /dev/null
+/*
+ SQLiteExpression.h
+
+ Copyright (C) 1999-2005 MDlink online service center GmbH and Helge Hess
+
+ Author: Helge Hess (helge@mdlink.de)
+
+ This file is part of the SQLite Adaptor 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; see the file COPYING.LIB.
+ If not, write to the Free Software Foundation,
+ 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+
+#ifndef ___SQLite3_SQLExpression_H___
+#define ___SQLite3_SQLExpression_H___
+
+#include <GDLAccess/EOSQLExpression.h>
+
+@class NSString, NSArray;
+@class EOSQLQualifier, EOAdaptorChannel;
+
+@interface SQLiteExpression : EOSQLExpression
+
++ (Class)selectExpressionClass;
+
+@end
+
+@interface SQLiteSelectSQLExpression : EOSelectSQLExpression
+{
+ BOOL lock;
+}
+
+- (id)selectExpressionForAttributes:(NSArray *)attributes
+ lock:(BOOL)flag
+ qualifier:(EOSQLQualifier *)qualifier
+ fetchOrder:(NSArray *)fetchOrder
+ channel:(EOAdaptorChannel *)channel;
+
+- (NSString *)fromClause;
+
+@end
+
+#endif /* ___SQLite3_SQLExpression_H___ */
--- /dev/null
+/*
+ SQLiteExpression.m
+
+ Copyright (C) 2003-2005 Helge Hess
+
+ Author: Helge Hess (helge.hess@opengroupware.org)
+
+ This file is part of the SQLite Adaptor 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; see the file COPYING.LIB.
+ If not, write to the Free Software Foundation,
+ 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+
+#include <Foundation/Foundation.h>
+#include <GDLAccess/GDLAccess.h>
+#include "SQLiteExpression.h"
+
+@implementation SQLiteExpression
+
++ (Class)selectExpressionClass {
+ return [SQLiteSelectSQLExpression class];
+}
+
+@end /* SQLiteExpression */
+
+@implementation SQLiteSelectSQLExpression
+
+- (id)selectExpressionForAttributes:(NSArray *)attributes
+ lock:(BOOL)flag
+ qualifier:(EOSQLQualifier *)qualifier
+ fetchOrder:(NSArray *)fetchOrder
+ channel:(EOAdaptorChannel *)channel {
+
+ lock = flag;
+ [super selectExpressionForAttributes:attributes
+ lock:flag
+ qualifier:qualifier
+ fetchOrder:fetchOrder
+ channel:channel];
+ return self;
+}
+
+- (NSString *)fromClause {
+ NSMutableString *fromClause;
+ NSEnumerator *enumerator;
+ BOOL first = YES;
+ id key;
+
+ fromClause = [NSMutableString stringWithCString:" "];
+ enumerator = [fromListEntities objectEnumerator];
+
+ // Compute the FROM list from all the aliases found in
+ // entitiesAndPropertiesAliases dictionary. Note that this dictionary
+ // contains entities and relationships. The last ones are there for
+ // flattened attributes over reflexive relationships.
+
+ while((key = [enumerator nextObject])) {
+ if(first) first = NO;
+ else [fromClause appendString:@", "];
+
+ [fromClause appendFormat:@"%@ %@",
+ [key isKindOfClass:[EORelationship class]]
+ ? [[key destinationEntity] externalName] // flattened attribute
+ : [key externalName], // EOEntity
+ [entitiesAndPropertiesAliases objectForKey:key]];
+
+#if 0
+ if (lock) [fromClause appendString:@" HOLDLOCK"];
+#endif
+ }
+
+ return fromClause;
+}
+
+@end /* SQLiteSelectSQLExpression */
+
+void __link_SQLiteExpression() {
+ // used to force linking of object file
+ __link_SQLiteExpression();
+}
--- /dev/null
+/*
+ SQLiteValues.h
+
+ Copyright (C) 1999-2005 MDlink online service center GmbH and Helge Hess
+
+ Author: Helge Hess (helge@mdlink.de)
+
+ This file is part of the SQLite Adaptor 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; see the file COPYING.LIB.
+ If not, write to the Free Software Foundation,
+ 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+
+#ifndef ___SQLite_Values_H___
+#define ___SQLite_Values_H___
+
+#import <Foundation/NSObject.h>
+#import <Foundation/NSString.h>
+#import <Foundation/NSData.h>
+#import <Foundation/NSDate.h>
+#import <GDLAccess/EONull.h>
+#import "SQLiteException.h"
+
+@class EOAttribute;
+@class SQLiteChannel;
+
+@interface SQLiteDataTypeMappingException : SQLiteException
+
+- (id)initWithObject:(id)_obj
+ forAttribute:(EOAttribute *)_attr
+ andSQLite3Type:(NSString *)_dt
+ inChannel:(SQLiteChannel *)_channel;
+
+@end
+
+@protocol SQLiteValues
+
++ (id)valueFromCString:(const char *)_cstr length:(int)_length
+ sqlite3Type:(NSString *)_type
+ attribute:(EOAttribute *)_attribute
+ adaptorChannel:(SQLiteChannel *)_channel;
+
++ (id)valueFromBytes:(const void *)_bytes length:(int)_length
+ sqlite3Type:(NSString *)_type
+ attribute:(EOAttribute *)_attribute
+ adaptorChannel:(SQLiteChannel *)_channel;
+
+- (NSString *)stringValueForSQLite3Type:(NSString *)_type
+ attribute:(EOAttribute *)_attribute;
+
+@end
+
+@interface NSString(SQLiteValues) < SQLiteValues >
+@end
+
+@interface NSNumber(SQLiteValues) < SQLiteValues >
+@end
+
+@interface NSData(SQLiteValues) < SQLiteValues >
+@end
+
+@interface NSCalendarDate(SQLiteValues) < SQLiteValues >
+@end
+
+@interface EONull(SQLiteValues)
+
+- (NSString *)stringValueForSQLite3Type:(NSString *)_type
+ attribute:(EOAttribute *)_attribute;
+
+@end
+
+#endif /* ___SQLite_Values_H___ */
--- /dev/null
+/*
+ SQLiteValues.m
+
+ Copyright (C) 1999-2005 MDlink online service center GmbH and Helge Hess
+
+ Author: Helge Hess (helge@mdlink.de)
+
+ This file is part of the SQLite Adaptor 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; see the file COPYING.LIB.
+ If not, write to the Free Software Foundation,
+ 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+
+#import "SQLiteValues.h"
+#import "common.h"
+
+@implementation SQLiteDataTypeMappingException
+
+- (id)initWithObject:(id)_obj
+ forAttribute:(EOAttribute *)_attr
+ andSQLite3Type:(NSString *)_dt
+ inChannel:(SQLiteChannel *)_channel;
+{
+ NSDictionary *ui;
+ NSString *typeName = nil;
+ NSString *r;
+
+ typeName = _dt;
+
+ if (typeName == nil)
+ typeName = [NSString stringWithFormat:@"Oid[%i]", _dt];
+
+ r = [NSString stringWithFormat:
+ @"mapping between %@<Class:%@> and "
+ @"SQLite type %@ is not supported",
+ [_obj description],
+ NSStringFromClass([_obj class]),
+ typeName];
+ ui = [NSDictionary dictionaryWithObjectsAndKeys:
+ _attr, @"attribute",
+ _channel, @"channel",
+ _obj, @"object",
+ nil];
+
+ [self setName:@"DataTypeMappingNotSupported"];
+ [self setReason:r];
+
+ [self setUserInfo:ui];
+ return self;
+}
+
+@end /* SQLiteDataTypeMappingException */
+
+@implementation NSNull(SQLiteValues)
+
+- (NSString *)stringValueForSQLite3Type:(NSString *)_type
+ attribute:(EOAttribute *)_attribute
+{
+ return @"null";
+}
+
+@end /* NSNull(SQLiteValues) */
+
+
+void __link_SQLiteValues() {
+ // used to force linking of object file
+ __link_SQLiteValues();
+}
--- /dev/null
+# $Id: Version,v 1.1 2004/06/14 14:27:44 helge Exp $
+
+SUBMINOR_VERSION:=8
--- /dev/null
+/*
+ common.h
+
+ Copyright (C) 1999-2005 MDlink online service center GmbH and Helge Hess
+
+ Author: Helge Hess (helge@mdlink.de)
+
+ This file is part of the SQLite3 Adaptor 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; see the file COPYING.LIB.
+ If not, write to the Free Software Foundation,
+ 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+
+#ifndef ___SQLite3_common_H___
+#define ___SQLite3_common_H___
+
+#import <objc/objc-api.h>
+
+#include <string.h>
+#include <strings.h>
+#include <stdlib.h>
+
+#import <Foundation/Foundation.h>
+
+#include <GDLAccess/GDLAccess.h>
+
+#endif /* ___SQLite3_common_H___ */
--- /dev/null
+{
+ databaseName = "hhtest1";
+}
--- /dev/null
+//
+
+#import <Foundation/Foundation.h>
+#import <GDLAccess/GDLAccess.h>
+#include <NGExtensions/NGExtensions.h>
+
+int main(int argc, char **argv, char **env) {
+ EOModel *m = nil;
+ EOAdaptor *a;
+ EOAdaptorContext *ctx;
+ EOAdaptorChannel *ch;
+ NSDictionary *conDict;
+ NSString *expr;
+
+ [NSProcessInfo initializeWithArguments:argv count:argc environment:env];
+
+ NS_DURING {
+
+ conDict = [NSDictionary dictionaryWithContentsOfFile:@"condict.plist"];
+ NSLog(@"condict is %@", conDict);
+
+ if ((a = [EOAdaptor adaptorWithName:@"SQLite3"]) == nil) {
+ NSLog(@"found no SQLite3 adaptor ..");
+ exit(1);
+ }
+
+ NSLog(@"got adaptor %@", a);
+ [a setConnectionDictionary:conDict];
+ NSLog(@"got adaptor with condict %@", a);
+
+ ctx = [a createAdaptorContext];
+ ch = [ctx createAdaptorChannel];
+
+#if 1
+ m = AUTORELEASE([[EOModel alloc] initWithContentsOfFile:@"test.eomodel"]);
+ if (m) {
+ [a setModel:m];
+ [a setConnectionDictionary:conDict];
+ }
+#endif
+
+ expr = [[NSUserDefaults standardUserDefaults] stringForKey:@"sql"];
+
+ NSLog(@"opening channel ..");
+
+ [ch setDebugEnabled:YES];
+
+ if ([ch openChannel]) {
+ NSLog(@"channel is open");
+
+ if ([ctx beginTransaction]) {
+ NSLog(@"began tx ..");
+
+ /* do something */
+ {
+ NSAutoreleasePool *pool = [NSAutoreleasePool new];
+ EOEntity *e;
+ EOSQLQualifier *q;
+ NSArray *attrs;
+
+#if 1
+ /* fetch some expr */
+
+ if (expr) {
+ if ([ch evaluateExpression:expr]) {
+ NSDictionary *record;
+
+ attrs = [ch describeResults];
+ NSLog(@"results: %@", attrs);
+
+ while ((record = [ch fetchAttributes:attrs withZone:nil]))
+ NSLog(@"fetched %@", record);
+ }
+ }
+#endif
+ /* fetch some doof records */
+
+ e = [m entityNamed:@"Doof"];
+ NSLog(@"entity: %@", e);
+ if (e == nil)
+ exit(1);
+
+ q = [e qualifier];
+ attrs = [e attributes];
+
+ if ([ch selectAttributes:attrs
+ describedByQualifier:q
+ fetchOrder:nil
+ lock:NO]) {
+ NSDictionary *record;
+
+ while ((record = [ch fetchAttributes:attrs withZone:nil])) {
+ NSLog(@"fetched %@ birthday %@",
+ [record valueForKey:@"pkey"],
+ [record valueForKey:@"companyId"]);
+ }
+ }
+ else
+ NSLog(@"Could not select ..");
+
+ /* fetch some team records */
+
+ if ((e = [m entityNamed:@"Team"])) {
+ q = [e qualifier];
+ attrs = [e attributes];
+
+ if ([ch selectAttributes:attrs
+ describedByQualifier:q
+ fetchOrder:nil
+ lock:NO]) {
+ NSDictionary *record;
+
+ while ((record = [ch fetchAttributes:attrs withZone:nil])) {
+ NSLog(@"fetched %@ birthday %@",
+ [record valueForKey:@"description"],
+ [record valueForKey:@"companyId"]);
+ }
+ }
+ else
+ NSLog(@"Could not select ..");
+ }
+
+ /* do some update */
+
+ if ((e = [m entityNamed:@"Person"])) {
+ attrs = [e attributes];
+ q = [[EOSQLQualifier alloc]
+ initWithEntity:e
+ qualifierFormat:@"%A='helge'", @"login"];
+ AUTORELEASE(q);
+
+ if ([ch selectAttributes:attrs
+ describedByQualifier:q
+ fetchOrder:nil
+ lock:NO]) {
+ NSDictionary *record;
+
+ record = [ch fetchAttributes:attrs withZone:nil];
+ }
+ else
+ NSLog(@"Could not select ..");
+ }
+
+ RELEASE(pool);
+ }
+
+ NSLog(@"committing tx ..");
+ if ([ctx commitTransaction])
+ NSLog(@" could commit.");
+ else
+ NSLog(@" commit failed.");
+ }
+
+ NSLog(@"closing channel ..");
+ [ch closeChannel];
+ }
+ }
+ NS_HANDLER {
+ fprintf(stderr, "exception: %s\n", [[localException description] cString]);
+ abort();
+ }
+ NS_ENDHANDLER;
+
+ return 0;
+}
--- /dev/null
+{
+ EOModelVersion = 1;
+ adaptorClassName = SQLiteAdaptor;
+ adaptorName = SQLite3;
+
+ entities = (
+ {
+ name = Doof;
+ externalName = doof;
+ className = EOGenericRecord;
+ primaryKeyAttributes = ( pkey );
+ attributesUsedForLocking = ( pkey );
+ classProperties = ( pkey );
+ attributes = (
+ {
+ valueClassName = NSNumber;
+ columnName = pkey;
+ name = pkey;
+ valueType = i;
+ externalType = INT; // t_id
+ },
+ );
+ }
+ );
+}