/// <summary> /// /// </summary> /// <param name="def"></param> /// <param name="field"></param> public void AddField(IElementDef def, SQLField field) { if (fFields == null) { fFields = new Dictionary<Object, Object>(); } fFields[def] = field; }
/// <summary> /// /// </summary> /// <param name="xPath"></param> /// <param name="field"></param> public void AddField(String xPath, SQLField field) { if (fFields == null) { fFields = new Dictionary <Object, Object>(); } fFields[xPath] = field; }
/// <summary> /// /// </summary> /// <param name="def"></param> /// <param name="field"></param> public void AddField(IElementDef def, SQLField field) { if (fFields == null) { fFields = new Dictionary <Object, Object>(); } fFields[def] = field; }
/// <summary> /// Adds SQLFields to represent each field rule in the specified MappingsContext /// </summary> /// <param name="context"></param> /// <param name="dialect"></param> public void AddFields(MappingsContext context, Dialect dialect) { foreach (FieldMapping mapping in context.FieldMappings) { Rule rule = mapping.fRule; if (rule is XPathRule) { TypeConverter converter = null; XPathRule xRule = (XPathRule)rule; IElementDef targetDef = xRule.LookupTargetDef(context.ObjectDef); if (targetDef != null) { converter = targetDef.TypeConverter; } if (converter == null) { converter = SifTypeConverters.STRING; } if (mapping.ValueSetID != null) { ValueSet vs = context.Mappings.GetValueSet(mapping.ValueSetID, true); if (vs != null) { //Create the lookup table for generating the SQL lookup StringBuilder buffer = new StringBuilder(); // e.g. CircRecord.PatronType{StudentPersonal=1;StaffPersonal=2} //buffer.Append( tablePrefix ); buffer.Append(mapping.FieldName); buffer.Append('{'); ValueSetEntry[] entries = vs.Entries; for (int a = 0; a < entries.Length; a++) { if (a > 0) { buffer.Append(';'); } buffer.Append(entries[a].Value); buffer.Append('='); ; buffer.Append(entries[a].Name); } buffer.Append('}'); SQLField f = new SQLField(buffer.ToString(), converter.DbType, dialect); AddField(xRule.XPath, f); continue; } } SQLField field = new SQLField(mapping.FieldName, converter.DbType, dialect); AddField(xRule.XPath, field); } } }
/// <summary> Return the text for a field value</summary> /// <param name="valu">The field value</param> /// <param name="def">The corresponding field definition from the Map passed to /// the <c>format</c> method /// </param> /// <returns> The implementation returns the field value in whatever form is /// appropriate to the implementation, using the supplied <i>def</i> /// Object if necessary to obtain additional field information /// </returns> public override string RenderValue(string valu, Object def) { try { // The elements in the Map are expected to be SQLField instances SQLField f = (SQLField)def; return(f.Render(DoValueSubstitution(valu, f.Name))); } catch (InvalidCastException cce) { throw new QueryFormatterException ("SQLQueryFormatter requires that the Map passed to the format method consist of SQLField instances (not " + cce.Message + " instances)", cce); } }
/// <summary> /// /// </summary> /// <param name="xPath"></param> /// <param name="field"></param> public void AddField(String xPath, SQLField field) { if (fFields == null) { fFields = new Dictionary<Object, Object>(); } fFields[xPath] = field; }
/// <summary> /// Adds SQLFields to represent each field rule in the specified MappingsContext /// </summary> /// <param name="context"></param> /// <param name="dialect"></param> public void AddFields( MappingsContext context, Dialect dialect ) { foreach ( FieldMapping mapping in context.FieldMappings ) { Rule rule = mapping.fRule; if ( rule is XPathRule ) { TypeConverter converter = null; XPathRule xRule = (XPathRule) rule; IElementDef targetDef = xRule.LookupTargetDef( context.ObjectDef ); if ( targetDef != null ) { converter = targetDef.TypeConverter; } if ( converter == null ) { converter = SifTypeConverters.STRING; } if ( mapping.ValueSetID != null ) { ValueSet vs = context.Mappings.GetValueSet( mapping.ValueSetID, true ); if ( vs != null ) { //Create the lookup table for generating the SQL lookup StringBuilder buffer = new StringBuilder(); // e.g. CircRecord.PatronType{StudentPersonal=1;StaffPersonal=2} //buffer.Append( tablePrefix ); buffer.Append( mapping.FieldName ); buffer.Append( '{' ); ValueSetEntry[] entries = vs.Entries; for ( int a = 0; a < entries.Length; a++ ) { if ( a > 0 ) { buffer.Append( ';' ); } buffer.Append( entries[a].Value ); buffer.Append( '=' ); ; buffer.Append( entries[a].Name ); } buffer.Append( '}' ); SQLField f = new SQLField( buffer.ToString(), converter.DbType, dialect ); AddField( xRule.XPath, f ); continue; } } SQLField field = new SQLField( mapping.FieldName, converter.DbType, dialect ); AddField( xRule.XPath, field ); } } }