DynamicQueryEngine/DynamicQueryEngine.cs
/// <summary>
/// Creates a new Insert Query object which is ready to use.
/// </summary>
/// <param name="fields">Array of EntityFieldCore objects to use to build the insert query</param>
/// <param name="fieldsPersistenceInfo">Array of IFieldPersistenceInfo objects to use to build the insert query</param>
/// <param name="query">The query object to fill.</param>
/// <param name="fieldToParameter">Hashtable which will contain after the call for each field the parameter which contains or will contain the field's value.</param>
/// <remarks>Generic version.</remarks>
/// <exception cref="System.ArgumentNullException">When fields is null or fieldsPersistenceInfo is null</exception>
/// <exception cref="System.ArgumentException">When fields contains no EntityFieldCore instances or fieldsPersistenceInfo is empty.</exception>
/// <exception cref="ORMQueryConstructionException">When there are no fields to insert in the fields list. This exception is to prevent
/// INSERT INTO table () VALUES () style queries.</exception>
Creates a new Insert Query object which is ready to use.
Creates a new Insert Query object which is ready to use .
protected override void CreateSingleTargetInsertDQ(IEntityFieldCore[] fields, IFieldPersistenceInfo[] fieldsPersistenceInfo,
															IActionQuery query, Dictionary<IEntityFieldCore, DbParameter> fieldToParameter )
		{
			TraceHelper.WriteLineIf(Switch.TraceInfo, "CreateSingleTargetInsertDQ", "Method Enter");
			QueryFragments fragments = new QueryFragments();
			fragments.AddFragments("INSERT INTO", this.Creator.CreateObjectName(fieldsPersistenceInfo[0]));
			var fieldNames = fragments.AddCommaDelimitedQueryFragments(true, fields?.Length ?? 0);
			fragments.AddFragment("VALUES");
			var valueFragments = fragments.AddCommaDelimitedQueryFragments(true, fields?.Length ?? 0);
			for (int i = 0; i < fields.Length; i++)
			{
				IEntityFieldCore field = fields[i];
				IFieldPersistenceInfo persistenceInfo = fieldsPersistenceInfo[i];
				bool isAutoTimestamp = false;
				if(!CheckIfFieldNeedsInsertAction(field))
				{
					if(persistenceInfo.SourceColumnDbType == "Timestamp" && field.IsReadOnly)
					{
						isAutoTimestamp = true;
					}
					else
					{
						continue;
					}
				}
				var fieldName = this.Creator.CreateFieldNameSimple(persistenceInfo, field.Name);
				fieldNames.AddFragment(fieldName);
				if(isAutoTimestamp)
				{
					valueFragments.AddFragment("PENDING_COMMIT_TIMESTAMP()");
				}
				else
				{
					AppendFieldToValueFragmentsForInsert(query, fieldToParameter, valueFragments, field, persistenceInfo);
				}
			}
			if(fieldNames.Count <= 0)
			{
				throw new ORMQueryConstructionException("The insert query doesn't contain any fields.");
			}
			query.SetCommandText(fragments.ToString());
			TraceHelper.WriteIf(Switch.TraceVerbose, query, "Generated Sql query");
			TraceHelper.WriteLineIf(Switch.TraceInfo, "CreateSingleTargetInsertDQ", "Method Exit");
		}
protected override void CreateSingleTargetInsertDQ ( IEntityFieldCore [ ] fields , IFieldPersistenceInfo [ ] fieldsPersistenceInfo , IActionQuery query , Dictionary < IEntityFieldCore , DbParameter > fieldToParameter ) { TraceHelper . WriteLineIf ( Switch . TraceInfo , " " , " " ) ; QueryFragments fragments = new QueryFragments ( ) ; fragments . AddFragments ( " " , this . Creator . CreateObjectName ( fieldsPersistenceInfo [ 0 ] ) ) ; var fieldNames = fragments . AddCommaDelimitedQueryFragments ( true , fields ? . Length ?? 0 ) ; fragments . AddFragment ( " " ) ; var valueFragments = fragments . AddCommaDelimitedQueryFragments ( true , fields ? . Length ?? 0 ) ; for ( int i = 0 ; i < fields . Length ; i ++ ) { IEntityFieldCore field = fields [ i ] ; IFieldPersistenceInfo persistenceInfo = fieldsPersistenceInfo [ i ] ; bool isAutoTimestamp = false ; if ( ! CheckIfFieldNeedsInsertAction ( field ) ) { if ( persistenceInfo . SourceColumnDbType == " " && field . IsReadOnly ) { isAutoTimestamp = true ; } else { continue ; } } var fieldName = this . Creator . CreateFieldNameSimple ( persistenceInfo , field . Name ) ; fieldNames . AddFragment ( fieldName ) ; if ( isAutoTimestamp ) { valueFragments . AddFragment ( " " ) ; } else { AppendFieldToValueFragmentsForInsert ( query , fieldToParameter , valueFragments , field , persistenceInfo ) ; } } if ( fieldNames . Count <= 0 ) { throw new ORMQueryConstructionException ( " " ) ; } query . SetCommandText ( fragments . ToString ( ) ) ; TraceHelper . WriteIf ( Switch . TraceVerbose , query , " " ) ; TraceHelper . WriteLineIf ( Switch . TraceInfo , " " , " " ) ; }
Creates a new Insert Query object which is ready to use.
Creates a new Insert Query object which is ready to use .
// if the type is timestamp, we'll accept the field, but have to call a function instead of passing a value through a parameter.  // no insert value needed
When fields is null or fieldsPersistenceInfo is null
When fields is null or fieldsPersistenceInfo is null
When fields contains no EntityFieldCore instances or fieldsPersistenceInfo is empty.
When fields contains no EntityFieldCore instances or fieldsPersistenceInfo is empty .
When there are no fields to insert in the fields list. This exception is to prevent
INSERT INTO table () VALUES () style queries.
When there are no fields to insert in the fields list . This exception is to prevent INSERT INTO table () VALUES () style queries .
fields
IEntityFieldCore[]
Array of EntityFieldCore objects to use to build the insert query
Array of EntityFieldCore objects to use to build the insert query
fieldsPersistenceInfo
IFieldPersistenceInfo[]
Array of IFieldPersistenceInfo objects to use to build the insert query
Array of IFieldPersistenceInfo objects to use to build the insert query
query
IActionQuery
The query object to fill.
The query object to fill .
fieldToParameter
Dictionary<IEntityFieldCore, DbParameter>
Hashtable which will contain after the call for each field the parameter which contains or will contain the field's value.
Hashtable which will contain after the call for each field the parameter which contains or will contain the field ' s value .
remarks
None