Tuukka Norri avatar Tuukka Norri committed b155a69

Documentation, regular expressions
- Added stubs for Mac OS X 10.6's new predicate and expression types.
- Moved regular expression functions to their own file (references #230).
- Updated documentation on getting entity descriptions.
- Fixed documentation on getting rows from a many-to-many helper table.
- Updated documnetation on unhandled predicate and expression types.
- Fixed documentation on function expressions.
- Fixed documentation on enabled relations.

Comments (0)

Files changed (8)

BaseTen.xcodeproj/project.pbxproj

 		531A215D0DE432F9006C757A /* BXPGManualCommitConnectionResetRecoveryAttempter.m in Sources */ = {isa = PBXBuildFile; fileRef = 531A215B0DE432F9006C757A /* BXPGManualCommitConnectionResetRecoveryAttempter.m */; };
 		5328754A0E1E515500CC507E /* BXPGSQLScriptReader.h in Headers */ = {isa = PBXBuildFile; fileRef = 532875480E1E515500CC507E /* BXPGSQLScriptReader.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		5328754B0E1E515500CC507E /* BXPGSQLScriptReader.m in Sources */ = {isa = PBXBuildFile; fileRef = 532875490E1E515500CC507E /* BXPGSQLScriptReader.m */; };
+		5329E7F6119F4845000EC6ED /* BXRegularExpressions.m in Sources */ = {isa = PBXBuildFile; fileRef = 5329E7F5119F4845000EC6ED /* BXRegularExpressions.m */; };
+		5329E7F8119F4878000EC6ED /* BXRegularExpressions.h in Headers */ = {isa = PBXBuildFile; fileRef = 5329E7F7119F4878000EC6ED /* BXRegularExpressions.h */; settings = {ATTRIBUTES = (Private, ); }; };
+		5329E7F9119F48BC000EC6ED /* pcre.h in Headers */ = {isa = PBXBuildFile; fileRef = 53C4E26B1194C757003FB842 /* pcre.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		5331CB5B0DEDA843003AF2A9 /* BXPGReconnectionRecoveryAttempter.h in Headers */ = {isa = PBXBuildFile; fileRef = 5331CB570DEDA843003AF2A9 /* BXPGReconnectionRecoveryAttempter.h */; };
 		5331CB5C0DEDA843003AF2A9 /* BXPGReconnectionRecoveryAttempter.m in Sources */ = {isa = PBXBuildFile; fileRef = 5331CB580DEDA843003AF2A9 /* BXPGReconnectionRecoveryAttempter.m */; };
 		53372E2A119AD74D0006F0A3 /* BXHostResolver.m in Sources */ = {isa = PBXBuildFile; fileRef = 53372E29119AD74D0006F0A3 /* BXHostResolver.m */; };
 		5328FB6B0C457AC4006DE171 /* BXRelationshipDescription.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BXRelationshipDescription.h; path = Sources/BXRelationshipDescription.h; sourceTree = "<group>"; };
 		5328FB6C0C457AC4006DE171 /* BXRelationshipDescription.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = BXRelationshipDescription.m; path = Sources/BXRelationshipDescription.m; sourceTree = "<group>"; };
 		5328FBD40C4580CD006DE171 /* BXForeignKey.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BXForeignKey.h; path = Sources/BXForeignKey.h; sourceTree = "<group>"; };
+		5329E7F5119F4845000EC6ED /* BXRegularExpressions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = BXRegularExpressions.m; path = Sources/BXRegularExpressions.m; sourceTree = "<group>"; };
+		5329E7F7119F4878000EC6ED /* BXRegularExpressions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BXRegularExpressions.h; path = Sources/BXRegularExpressions.h; sourceTree = "<group>"; };
 		532D60FF0B9454110028E90B /* BXConnectionSetupManagerProtocol.h */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.h; fileEncoding = 4; lineEnding = 0; name = BXConnectionSetupManagerProtocol.h; path = Sources/BXConnectionSetupManagerProtocol.h; sourceTree = "<group>"; };
 		5331CB570DEDA843003AF2A9 /* BXPGReconnectionRecoveryAttempter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BXPGReconnectionRecoveryAttempter.h; path = Sources/BXPGReconnectionRecoveryAttempter.h; sourceTree = "<group>"; };
 		5331CB580DEDA843003AF2A9 /* BXPGReconnectionRecoveryAttempter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = BXPGReconnectionRecoveryAttempter.m; path = Sources/BXPGReconnectionRecoveryAttempter.m; sourceTree = "<group>"; };
 				5339AB920A7542EC00994B1A /* BXException.m */,
 				53372E2B119AD77C0006F0A3 /* BXHostResolver.h */,
 				53372E29119AD74D0006F0A3 /* BXHostResolver.m */,
+				5329E7F7119F4878000EC6ED /* BXRegularExpressions.h */,
+				5329E7F5119F4845000EC6ED /* BXRegularExpressions.m */,
 				53666CC20E1CD8D20028DBEA /* PGTSHOM.h */,
 				53666CC30E1CD8D20028DBEA /* PGTSHOM.m */,
 				53937B650EFD097700510DBD /* PGTSInvocationRecorder.h */,
 				530A6A561199B9CA00ED63FD /* PGTSAsynchronousConnector.h in Headers */,
 				530A6A581199B9CA00ED63FD /* PGTSSynchronousConnector.h in Headers */,
 				53372E2C119AD77C0006F0A3 /* BXHostResolver.h in Headers */,
+				5329E7F8119F4878000EC6ED /* BXRegularExpressions.h in Headers */,
+				5329E7F9119F48BC000EC6ED /* pcre.h in Headers */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
 				530A6A571199B9CA00ED63FD /* PGTSAsynchronousConnector.m in Sources */,
 				530A6A591199B9CA00ED63FD /* PGTSSynchronousConnector.m in Sources */,
 				53372E2A119AD74D0006F0A3 /* BXHostResolver.m in Sources */,
+				5329E7F6119F4845000EC6ED /* BXRegularExpressions.m in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

Sources/BXPredicateVisitor.h

 - (BXPGExpressionValueType *) visitUnionSetExpression: (NSExpression *) expression;
 - (BXPGExpressionValueType *) visitIntersectSetExpression: (NSExpression *) expression;
 - (BXPGExpressionValueType *) visitMinusSetExpression: (NSExpression *) expression;
+- (BXPGExpressionValueType *) visitBlockExpression: (NSExpression *) expression;
 - (BXPGExpressionValueType *) visitUnknownExpression: (NSExpression *) expression;
 @end
 

Sources/BXPredicateVisitor.m

 	return retval;
 }
 
+- (BXPGExpressionValueType *) visitBlockExpression: (NSExpression *) expression
+{
+	BXPGExpressionValueType *retval = nil;
+	return retval;
+}
+
 - (BXPGExpressionValueType *) visitUnknownExpression: (NSExpression *) expression
 {
 	BXPGExpressionValueType* retval = nil;

Sources/BXRegularExpressions.h

+//
+// BXRegularExpressions.h
+// BaseTen
+//
+// Copyright (C) 2010 Marko Karppinen & Co. LLC.
+//
+// Before using this software, please review the available licensing options
+// by visiting http://www.karppinen.fi/baseten/licensing/ or by contacting
+// us at sales@karppinen.fi. Without an additional license, this software
+// may be distributed only in compliance with the GNU General Public License.
+//
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License, version 2.0,
+// as published by the Free Software Foundation.
+//
+// This program 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 General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+//
+// $Id$
+//
+
+
+#import <BaseTen/pcre.h>
+#import <BaseTen/BXExport.h>
+
+
+struct regular_expression_st 
+{
+	pcre* re_expression;
+	pcre_extra* re_extra;
+	char* re_pattern;
+};
+
+
+BX_EXPORT void BXRegularExpressionCompile (struct regular_expression_st *re, const char *pattern);
+BX_EXPORT void BXRegularExpressionFree (struct regular_expression_st *re);

Sources/BXRegularExpressions.m

+//
+// BXRegularExpressions.m
+// BaseTen
+//
+// Copyright (C) 2008-2010 Marko Karppinen & Co. LLC.
+//
+// Before using this software, please review the available licensing options
+// by visiting http://www.karppinen.fi/baseten/licensing/ or by contacting
+// us at sales@karppinen.fi. Without an additional license, this software
+// may be distributed only in compliance with the GNU General Public License.
+//
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License, version 2.0,
+// as published by the Free Software Foundation.
+//
+// This program 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 General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+//
+// $Id$
+//
+
+
+#import "BXRegularExpressions.h"
+#import "BXLogger.h"
+
+
+void
+BXRegularExpressionCompile (struct regular_expression_st *re, const char *pattern)
+{
+	const int options = PCRE_UTF8 | PCRE_MULTILINE | PCRE_DOLLAR_ENDONLY;
+	const char* error = NULL;
+	int errorOffset = 0;
+	if ((re->re_expression = pcre_compile (pattern, options, &error, &errorOffset, NULL)))
+	{
+		re->re_extra = pcre_study (re->re_expression, 0, &error);
+		if (error)
+		{
+			BXLogError (@"Failed to study pattern'%s': %s", pattern, error);
+			pcre_free (re->re_expression);
+		}
+		else
+		{
+			re->re_pattern = strdup (pattern);
+		}
+	}
+	else
+	{
+		BXLogError (@"Failed to compile pattern at offset %d '%s': %s", errorOffset, pattern, error);
+	}
+}
+
+
+void
+BXRegularExpressionFree (struct regular_expression_st *re)
+{
+	if (re)
+	{
+		if (re->re_expression)
+		{
+			pcre_free (re->re_expression);
+			re->re_expression = NULL;
+		}
+		
+		if (re->re_extra)
+		{
+			pcre_free (re->re_extra);
+			re->re_extra = NULL;
+		}
+		
+		if (re->re_pattern)
+		{
+			free (re->re_pattern);
+			re->re_pattern = NULL;
+		}
+	}
+}

Sources/BaseTen.h

  *     BXDatabaseContext* ctx = [[BXDatabaseContext alloc] initWithDatabaseURI: databaseURI];
  * 
  *     [ctx connectSync: NULL];
- *     BXEntityDescription* entity = [ctx entityForTable: @"table" error: NULL];
+ *     BXEntityDescription* entity = [[ctx databaseObjectModel] entityForTable: @"table"];
  *     NSArray* result = [ctx executeFetchForEntity: entity withPredicate: nil error: NULL];
  *
  *     for (BXDatabaseObject* object in result)
  *     BXDatabaseContext* ctx = [[BXDatabaseContext alloc] initWithDatabaseURI: databaseURI];
  * 
  *     [ctx connectSync: NULL];
- *     BXEntityDescription* entity = [ctx entityForTable: @"table" error: NULL];
+ *     BXEntityDescription* entity = [[ctx databaseObjectModel] entityForTable: @"table"];
  *     NSArray* result = [ctx executeFetchForEntity: entity withPredicate: nil error: NULL];
  *
  *     for (BXDatabaseObject* object in result)
  *
  * \latexonly
  * \begin{lstlisting}
- * BXEntityDescription* entity = [ctx entityForTable: @"table" error: NULL];
+ * BXEntityDescription* entity = [[ctx databaseObjectModel] entityForTable: @"table"];
  * \end{lstlisting}
  * \endlatexonly
  * \htmlonly
- * <code>BXEntityDescription* entity = [ctx entityForTable: @"table" error: NULL];</code>
+ * <code>BXEntityDescription* entity = [[ctx databaseObjectModel] entityForTable: @"table"];</code>
  * \endhtmlonly
  *
  * BXEntityDescriptions are used to specify tables for fetches. For getting a specific 
- * entity description, BXDatabaseContext has two methods: 
- * -entityForTable:error:
+ * entity description, BXDatabaseObjectModel has two methods: 
+ * -entityForTable:
  * and
- * -entityForTable:inSchema:error:.
+ * -entityForTable:inSchema:.
  * Entity descriptions may be accessed before making a
  * connection in which case the database context will check their existence on connect.
  *
  * Any two foreign keys 
  * in one table will be interpreted as a many-to-many relationship, if they also form the table's 
  * primary key. Objects from the helper table may be retrieved as with one-to-many relationships:<br>
- * <tt>[aPerson valueForKey:\@"person_title_rel"]</tt>.
+ * <tt>[aPerson valueForKey:\@"person_title_relSet"]</tt>.
  */
 
 /**
  * \page predicates Predicates
  *
+ * Cocoa predicates are used to fetch objects that match certain criteria. Key paths in predicates 
+ * correspond to entity attributes and relationships.
+ *
  * Most types of predicates and expressions are converted to SQL and sent to the database server.
  * Others cause the returned object set to be filtered again on the client side. Specifically, the following
  * use cases work in this manner: The affected part of the predicate is replaced with <em>true</em> (or <em>false</em>, 
  * after it has been received.
  *
  * <ul>
- *     <li>Use of NSDiacriticInsensitivePredicateOption</li>
  *     <li>Use of NSCustomSelectorPredicateOperatorType</li>
- *     <li>Use of NSSubqueryExpressionType</li>
- *     <li>Use of NSUnionSetExpressionType</li>
- *     <li>Use of NSIntersectSetExpressionType</li>
- *     <li>Use of NSMinusSetExpressionType</li>
  *     <li>A modifier other than NSDirectPredicateModifier in combination with any of the following:
  *         <ul>
  *             <li>NSBeginsWithPredicateOperatorType</li>
  *             <li>NSContainsPredicateOperatorType</li>
  *             <li>NSInPredicateOperatorType</li>
  *         </ul>
+ *     </li> 
+ *     <li>Use of any of the following predicate options:
+ *         <ul>
+ *             <li>NSDiacriticInsensitivePredicateOption</li>
+ *             <li>NSNormalizedPredicateOption</li>
+ *             <li>NSLocaleSensitivePredicateOption</li>
+ *         </ul>
+ *     </li>
+ *     <li>Use of any of the following expression types:
+ *         <ul>
+ *             <li>NSSubqueryExpressionType</li>
+ *             <li>NSUnionSetExpressionType</li>
+ *             <li>NSIntersectSetExpressionType</li>
+ *             <li>NSMinusSetExpressionType</li>
+ *             <li>NSBlockExpressionType</li>
+ *         </ul>
+ *     </li>
+ *     <li>Use of a function expression with a custom target and selector</li>
+ *     <li>Use of a function expression with any of the following predefined selectors:
+ *         <ul>
+ *             <li>average:</li>
+ *             <li>castObject:toType:</li>
+ *             <li>max:</li>
+ *             <li>median:</li>
+ *             <li>min:</li>
+ *             <li>mode:</li>
+ *             <li>random</li>
+ *             <li>random:</li>
+ *             <li>randomn:</li>
+ *             <li>stddev:</li>
+ *         </ul>
  *     </li>
  * </ul>
  */
  * \li Altering relations' names after having them enabled will not work. To rename relations, they need
  *     to be disabled first and re-enabled afterwards.
  * \li Altering relations' primary keys will not work. Again, disabling and re-enabling is required.
- * \li Altering relations' columns keys will not work. Again, disabling and re-enabling is required.
+ * \li Altering relations' columns will not work. Again, disabling and re-enabling is required.
  * \li Altering relations' foreign keys causes BaseTen's relationship information to become out-of-date
  *     and needing to be refreshed.
  *

Sources/NSExpression+PGTSAdditions.m

 			retval = [visitor visitMinusSetExpression: self];
 			break;
 			
+		case NSBlockExpressionType:
+			retval = [visitor visitBlockExpression: self];
+			break;
+			
 		default:
 			retval = [visitor visitUnknownExpression: self];
 			break;

Sources/PGTSDates.m

 //
 
 
-#import "pcre.h"
 #import "PGTSDates.h"
 #import "PGTSConnection.h"
 #import "PGTSTypeDescription.h"
 #import "BXLogger.h"
 #import "BXArraySize.h"
+#import "BXRegularExpressions.h"
 
 
 #define kOvectorSize 64
 
 
-struct regular_expression_st 
-{
-	pcre* re_expression;
-	pcre_extra* re_extra;
-	char* re_pattern;
-};
-
-
 static struct regular_expression_st gTimestampExp = {};
 static struct regular_expression_st gDateExp = {};
 static struct regular_expression_st gTimeExp = {};
 }
 
 
-static void
-Compile (struct regular_expression_st* re, const char* pattern)
-{
-	const int options = PCRE_UTF8 | PCRE_MULTILINE | PCRE_DOLLAR_ENDONLY;
-	const char* error = NULL;
-	int errorOffset = 0;
-	if ((re->re_expression = pcre_compile (pattern, options, &error, &errorOffset, NULL)))
-	{
-		re->re_extra = pcre_study (re->re_expression, 0, &error);
-		if (error)
-		{
-			BXLogError (@"Failed to study pattern'%s': %s", pattern, error);
-			pcre_free (re->re_expression);
-		}
-		else
-		{
-			re->re_pattern = strdup (pattern);
-		}
-	}
-	else
-	{
-		BXLogError (@"Failed to compile pattern at offset %d '%s': %s", errorOffset, pattern, error);
-	}
-}
-
-
 static NSDate*
 CopyDate (struct regular_expression_st* re, const char* subject, int* ovector, int status)
 {
 		//There might be a trailing 'BC' for years before 1 AD.
 		
 		const char* pattern = "^(?<y>\\d{4,7})-(?<m>\\d{2})-(?<d>\\d{2})(?<e> BC)?$";
-		Compile (&gDateExp, pattern);
+		BXRegularExpressionCompile (&gDateExp, pattern);
 	}
 }
 
 		"^(?<H>\\d{2}):(?<M>\\d{2}):(?<S>\\d{2})"                             //Time
 		"(?<frac>\\.\\d{1,6})?"                                               //Fraction
 		"((?<tzd>[+-])(?<tzh>\\d{2})(:(?<tzm>\\d{2})(:(?<tzs>\\d{2}))?)?)?$"; //Time zone
-		Compile (&gTimeExp, pattern);
+		BXRegularExpressionCompile (&gTimeExp, pattern);
 	}
 }
 
 		"(?<frac>\\.\\d{1,6})?"                                             //Fraction
 		"((?<tzd>[+-])(?<tzh>\\d{2})(:(?<tzm>\\d{2})(:(?<tzs>\\d{2}))?)?)?" //Time zone
 		"(?<e> BC)?$";                                                      //Era specifier
-		Compile (&gTimestampExp, pattern);
+		BXRegularExpressionCompile (&gTimestampExp, pattern);
 	}
 }
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.