trunk/src/LythumOSL.Core/Data/Database.cs
/// <summary>
/// Gets values from datarow, with some preformatting by DbFieldInfo information
/// </summary>
/// <param name="info">Database metadata info</param>
/// <param name="r">DataRow</param>
/// <param name="fieldInfo">Fields information</param>
/// <param name="forWhat">For which query type are those fields</param>
/// <returns>fields array</returns>
Gets values from datarow, with some preformatting by DbFieldInfo information
Gets values from datarow with some preformatting by DbFieldInfo information
public static string[] GetValues (DatabasesInfo info, DataRow r, DbFieldInfo[] fieldInfo, ForWhat forWhat)
		{
			List<string> retVal = new List<string> ();
			if (fieldInfo != null)
			{
				foreach (DbFieldInfo i in fieldInfo)
				{
					if (r.Table.Columns.Contains (i.Name))
					{
						Type columnType = r.Table.Columns[i.Name].DataType;
						if ((i.UpdateMode == DbFieldUpdateMode.NowEverytime) ||
							(i.UpdateMode == DbFieldUpdateMode.NowOnInsert && forWhat == ForWhat.ForInsert) ||
							(i.UpdateMode == DbFieldUpdateMode.NowOnUpdate && forWhat == ForWhat.ForUpdate))
						{
							retVal.Add (info.FunctionNow);
						}
						else if (i.UpdateMode == DbFieldUpdateMode.NewGuidOnInsert && forWhat == ForWhat.ForInsert ||
							i.UpdateMode == DbFieldUpdateMode.NewGuidOnUpdate && forWhat == ForWhat.ForUpdate)
						{
							retVal.Add ("'" + NewGuid() + "'");
						}
						else if ((DBNull.Value.Equals (r[i.Name]) || r[i.Name] == null) )
						{
							switch (i.UpdateMode)
							{
								default:
								case DbFieldUpdateMode.ValueEmptyToNull:
									retVal.Add ("NULL");
									break;
								case DbFieldUpdateMode.ValueEmptyToZero:
									retVal.Add ("0");
									break;
							}
						}
						else 
						{
							if (columnType == typeof (decimal) ||
								columnType == typeof (double) ||
								columnType == typeof (float))
							{
								retVal.Add ("'" + r[i.Name].ToString ().Replace (",", ".") + "'");
							}
							else
							{
								retVal.Add ("'" + Fix.FixString (r[i.Name].ToString ()) + "'");
							}
						}
					}
				}
			}
			return retVal.ToArray();
		}
public static string [ ] GetValues ( DatabasesInfo info , DataRow r , DbFieldInfo [ ] fieldInfo , ForWhat forWhat ) { List < string > retVal = new List < string > ( ) ; if ( fieldInfo != null ) { foreach ( DbFieldInfo i in fieldInfo ) { if ( r . Table . Columns . Contains ( i . Name ) ) { Type columnType = r . Table . Columns [ i . Name ] . DataType ; if ( ( i . UpdateMode == DbFieldUpdateMode . NowEverytime ) || ( i . UpdateMode == DbFieldUpdateMode . NowOnInsert && forWhat == ForWhat . ForInsert ) || ( i . UpdateMode == DbFieldUpdateMode . NowOnUpdate && forWhat == ForWhat . ForUpdate ) ) { retVal . Add ( info . FunctionNow ) ; } else if ( i . UpdateMode == DbFieldUpdateMode . NewGuidOnInsert && forWhat == ForWhat . ForInsert || i . UpdateMode == DbFieldUpdateMode . NewGuidOnUpdate && forWhat == ForWhat . ForUpdate ) { retVal . Add ( " " + NewGuid ( ) + " " ) ; } else if ( ( DBNull . Value . Equals ( r [ i . Name ] ) || r [ i . Name ] == null ) ) { switch ( i . UpdateMode ) { default : case DbFieldUpdateMode . ValueEmptyToNull : retVal . Add ( " " ) ; break ; case DbFieldUpdateMode . ValueEmptyToZero : retVal . Add ( " " ) ; break ; } } else { if ( columnType == typeof ( decimal ) || columnType == typeof ( double ) || columnType == typeof ( float ) ) { retVal . Add ( " " + r [ i . Name ] . ToString ( ) . Replace ( " " , " " ) + " " ) ; } else { retVal . Add ( " " + Fix . FixString ( r [ i . Name ] . ToString ( ) ) + " " ) ; } } } } } return retVal . ToArray ( ) ; }
Gets values from datarow, with some preformatting by DbFieldInfo information
Gets values from datarow with some preformatting by DbFieldInfo information
// dates NOW()/GETDATE() // New guid // NULLS // if(i.UpdateMode == DbFieldUpdateMode.PureValue)
None
info
DatabasesInfo
Database metadata info
Database metadata info
r
DataRow
None
fieldInfo
DbFieldInfo[]
None
forWhat
ForWhat
For which query type are those fields
For which query type are those fields