public static DbParameter NewPar(string Nome, object Valore, DbType tipo) { DbParameter o = null; if (DataBaseAttuale == DataBase.Access) { o = new System.Data.OleDb.OleDbParameter(Nome, tipo); } else if (DataBaseAttuale == DataBase.SQLite) { if (tipo == DbType.Date || tipo == DbType.DateTime) { //"YYYY-MM-DD HH:MM:SS.SSS" Valore = ((DateTime)Valore).ToString("yyyy-MM-dd HH:mm:ss.fff"); tipo = DbType.String; } #if __MonoCS__ o = new Mono.Data.Sqlite.SqliteParameter(Nome, tipo); #else o = new System.Data.SQLite.SQLiteParameter(Nome, tipo); #endif } o.Value = Valore; return(o); }
public DbParameter NewPar(string Nome, object Valore) { DbParameter o = null; if (Valore is DateTime) { switch (DataBaseAttuale) { case DataBase.Access: o = new OleDbParameter(Nome, DbType.DateTime); break; case DataBase.SQLite: Valore = cGB.DateToSQLite((DateTime)Valore); #if __MonoCS__ o = new Mono.Data.Sqlite.SqliteParameter(Nome, DbType.String); #else o = new SQLiteParameter(Nome, DbType.String); #endif break; } o.Value = Valore; } else { switch (DataBaseAttuale) { case DataBase.Access: o = new OleDbParameter(Nome, Valore); break; case DataBase.SQLite: #if __MonoCS__ o = new Mono.Data.Sqlite.SqliteParameter(Nome, Valore); #else o = new SQLiteParameter(Nome, Valore); #endif break; } } return(o); }
public static DbParameter NewPar(string Nome, object Valore) { DbParameter o = null; if (Valore is DateTime) { if (DataBaseAttuale == DataBase.Access) { o = new System.Data.OleDb.OleDbParameter(Nome, DbType.DateTime); } else if (DataBaseAttuale == DataBase.SQLite) { Valore = cGB.DateToSQLite((DateTime)Valore); //Valore = ((DateTime)Valore).ToString("yyyy-MM-dd HH:mm:ss.fff"); #if __MonoCS__ o = new Mono.Data.Sqlite.SqliteParameter(Nome, DbType.String); #else o = new System.Data.SQLite.SQLiteParameter(Nome, DbType.String); #endif } o.Value = Valore; } else { if (DataBaseAttuale == DataBase.Access) { o = new System.Data.OleDb.OleDbParameter(Nome, Valore); } else if (DataBaseAttuale == DataBase.SQLite) #if __MonoCS__ { o = new Mono.Data.Sqlite.SqliteParameter(Nome, Valore); } #else { o = new System.Data.SQLite.SQLiteParameter(Nome, Valore); } #endif } return(o); }
/// <summary> /// gets routes from gpsd log file /// </summary> /// <param name="gpsdLogFile"></param> /// <param name="start">start time(UTC) of route, null to read from very start</param> /// <param name="end">end time(UTC) of route, null to read to the very end</param> /// <param name="maxPositionDilutionOfPrecision">max value of PositionDilutionOfPrecision, null to get all</param> /// <returns></returns> public static IEnumerable <List <GpsLog> > GetRoutesFromMobileLog(string gpsdLogFile, DateTime?start, DateTime?end, double?maxPositionDilutionOfPrecision) { #if SQLite using (SQLiteConnection cn = new SQLiteConnection()) { #if !MONO cn.ConnectionString = string.Format("Data Source=\"{0}\";FailIfMissing=True;", gpsdLogFile); #else cn.ConnectionString = string.Format("Version=3,URI=file://{0},FailIfMissing=True", gpsdLogFile); #endif cn.Open(); { using (DbCommand cmd = cn.CreateCommand()) { cmd.CommandText = "SELECT * FROM GPS "; if (start.HasValue) { cmd.CommandText += "WHERE TimeUTC >= @t1 "; SQLiteParameter lookupValue = new SQLiteParameter("@t1", start); cmd.Parameters.Add(lookupValue); } if (end.HasValue) { if (!start.HasValue) { cmd.CommandText += "WHERE "; } else { cmd.CommandText += "AND "; } cmd.CommandText += "TimeUTC <= @t2 "; SQLiteParameter lookupValue = new SQLiteParameter("@t2", end); cmd.Parameters.Add(lookupValue); } if (maxPositionDilutionOfPrecision.HasValue) { if (!start.HasValue && !end.HasValue) { cmd.CommandText += "WHERE "; } else { cmd.CommandText += "AND "; } cmd.CommandText += "(PositionDilutionOfPrecision <= @p3)"; SQLiteParameter lookupValue = new SQLiteParameter("@p3", maxPositionDilutionOfPrecision); cmd.Parameters.Add(lookupValue); } using (DbDataReader rd = cmd.ExecuteReader()) { List <GpsLog> points = new List <GpsLog>(); long lastSessionCounter = -1; while (rd.Read()) { GpsLog log = new GpsLog(); { log.TimeUTC = (DateTime)rd["TimeUTC"]; log.SessionCounter = (long)rd["SessionCounter"]; log.Delta = rd["Delta"] as double?; log.Speed = rd["Speed"] as double?; log.SeaLevelAltitude = rd["SeaLevelAltitude"] as double?; log.EllipsoidAltitude = rd["EllipsoidAltitude"] as double?; log.SatellitesInView = rd["SatellitesInView"] as System.Byte?; log.SatelliteCount = rd["SatelliteCount"] as System.Byte?; log.Position = new PointLatLng((double)rd["Lat"], (double)rd["Lng"]); log.PositionDilutionOfPrecision = rd["PositionDilutionOfPrecision"] as double?; log.HorizontalDilutionOfPrecision = rd["HorizontalDilutionOfPrecision"] as double?; log.VerticalDilutionOfPrecision = rd["VerticalDilutionOfPrecision"] as double?; log.FixQuality = (FixQuality)((byte)rd["FixQuality"]); log.FixType = (FixType)((byte)rd["FixType"]); log.FixSelection = (FixSelection)((byte)rd["FixSelection"]); } if (log.SessionCounter - lastSessionCounter != 1 && points.Count > 0) { List <GpsLog> ret = new List <GpsLog>(points); points.Clear(); { yield return(ret); } } points.Add(log); lastSessionCounter = log.SessionCounter; } if (points.Count > 0) { List <GpsLog> ret = new List <GpsLog>(points); points.Clear(); { yield return(ret); } } points.Clear(); points = null; rd.Close(); } } } cn.Close(); } #else return(null); #endif }
public int Add(Mono.Data.Sqlite.SqliteParameter parameter) { throw null; }
public SQLiteParameter(string str, System.Data.DbType type) { __parameter = new Mono.Data.Sqlite.SqliteParameter (str, type); }
public SQLiteParameter(string str, System.Data.DbType type) { __parameter = new Mono.Data.Sqlite.SqliteParameter(str, type); }
/// <summary> /// gets routes from gpsd log file /// </summary> /// <param name="gpsdLogFile"></param> /// <param name="start">start time(UTC) of route, null to read from very start</param> /// <param name="end">end time(UTC) of route, null to read to the very end</param> /// <param name="maxPositionDilutionOfPrecision">max value of PositionDilutionOfPrecision, null to get all</param> /// <returns></returns> public static IEnumerable<List<GpsLog>> GetRoutesFromMobileLog(string gpsdLogFile, DateTime? start, DateTime? end, double? maxPositionDilutionOfPrecision) { #if SQLite using(SQLiteConnection cn = new SQLiteConnection()) { #if !MONO cn.ConnectionString = string.Format("Data Source=\"{0}\";FailIfMissing=True;", gpsdLogFile); #else cn.ConnectionString = string.Format("Version=3,URI=file://{0},FailIfMissing=True", gpsdLogFile); #endif cn.Open(); { using(DbCommand cmd = cn.CreateCommand()) { cmd.CommandText = "SELECT * FROM GPS "; if(start.HasValue) { cmd.CommandText += "WHERE TimeUTC >= @t1 "; SQLiteParameter lookupValue = new SQLiteParameter("@t1", start); cmd.Parameters.Add(lookupValue); } if(end.HasValue) { if(!start.HasValue) { cmd.CommandText += "WHERE "; } else { cmd.CommandText += "AND "; } cmd.CommandText += "TimeUTC <= @t2 "; SQLiteParameter lookupValue = new SQLiteParameter("@t2", end); cmd.Parameters.Add(lookupValue); } if(maxPositionDilutionOfPrecision.HasValue) { if(!start.HasValue && !end.HasValue) { cmd.CommandText += "WHERE "; } else { cmd.CommandText += "AND "; } cmd.CommandText += "(PositionDilutionOfPrecision <= @p3)"; SQLiteParameter lookupValue = new SQLiteParameter("@p3", maxPositionDilutionOfPrecision); cmd.Parameters.Add(lookupValue); } using(DbDataReader rd = cmd.ExecuteReader()) { List<GpsLog> points = new List<GpsLog>(); long lastSessionCounter = -1; while(rd.Read()) { GpsLog log = new GpsLog(); { log.TimeUTC = (DateTime)rd["TimeUTC"]; log.SessionCounter = (long)rd["SessionCounter"]; log.Delta = rd["Delta"] as double?; log.Speed = rd["Speed"] as double?; log.SeaLevelAltitude = rd["SeaLevelAltitude"] as double?; log.EllipsoidAltitude = rd["EllipsoidAltitude"] as double?; log.SatellitesInView = rd["SatellitesInView"] as System.Byte?; log.SatelliteCount = rd["SatelliteCount"] as System.Byte?; log.Position = new PointLatLng((double)rd["Lat"], (double)rd["Lng"]); log.PositionDilutionOfPrecision = rd["PositionDilutionOfPrecision"] as double?; log.HorizontalDilutionOfPrecision = rd["HorizontalDilutionOfPrecision"] as double?; log.VerticalDilutionOfPrecision = rd["VerticalDilutionOfPrecision"] as double?; log.FixQuality = (FixQuality)((byte)rd["FixQuality"]); log.FixType = (FixType)((byte)rd["FixType"]); log.FixSelection = (FixSelection)((byte)rd["FixSelection"]); } if(log.SessionCounter - lastSessionCounter != 1 && points.Count > 0) { List<GpsLog> ret = new List<GpsLog>(points); points.Clear(); { yield return ret; } } points.Add(log); lastSessionCounter = log.SessionCounter; } if(points.Count > 0) { List<GpsLog> ret = new List<GpsLog>(points); points.Clear(); { yield return ret; } } points.Clear(); points = null; rd.Close(); } } } cn.Close(); } #else return null; #endif }
/// <summary> /// 生成SQL语句参数对象数组 /// </summary> /// <typeparam name="T">实体类型</typeparam> /// <param name="obj"></param> /// <param name="dbtype">数据库类型</param> /// <param name="fields">字段,用空格隔开多个字段。参数名称需与字段名称一致!</param> /// <returns></returns> public static DbParameter[] GetDbParameter <T>(this T obj, DataBaseType dbtype, String fields) { DbParameter[] parameters; String[] filedArray; Type type; PropertyInfo pro; object proValue; type = obj.GetType(); filedArray = fields.Split(' ', ','); //初始化参数数组 int fieldCount = filedArray.Length; switch (dbtype) { case DataBaseType.MonoSQLite: parameters = new Mono.Data.Sqlite.SqliteParameter[fieldCount]; break; case DataBaseType.OLEDB: parameters = new System.Data.OleDb.OleDbParameter[fieldCount]; break; case DataBaseType.SQLite: parameters = new System.Data.SQLite.SQLiteParameter[fieldCount]; break; case DataBaseType.MySQL: parameters = new MySql.Data.MySqlClient.MySqlParameter[fieldCount]; break; default: case DataBaseType.SQLServer: parameters = new System.Data.SqlClient.SqlParameter[fieldCount]; break; } string fieldName; for (int i = 0; i < fieldCount; i++) { fieldName = filedArray[i]; pro = type.GetProperty(fieldName, BindingFlags.Public | BindingFlags.Instance | BindingFlags.IgnoreCase); if (pro == null) { throw new Exception(String.Format("对象不存在属性:{0}", fieldName)); } //获取对象的值 proValue = pro.GetValue(obj, null); if (proValue == null) { throw new Exception(String.Format("对象属性必须赋值,属性名称:{0}", fieldName)); } switch (dbtype) { case DataBaseType.MonoSQLite: parameters[i] = new Mono.Data.Sqlite.SqliteParameter(String.Format("@{0}", fieldName), proValue); break; case DataBaseType.SQLite: parameters[i] = new System.Data.SQLite.SQLiteParameter(String.Format("@{0}", fieldName), proValue); break; case DataBaseType.OLEDB: parameters[i] = new System.Data.OleDb.OleDbParameter(String.Format("@{0}", fieldName), proValue); break; case DataBaseType.MySQL: parameters[i] = new MySql.Data.MySqlClient.MySqlParameter(String.Format("@{0}", fieldName), proValue); break; default: case DataBaseType.SQLServer: parameters[i] = new System.Data.SqlClient.SqlParameter(String.Format("@{0}", fieldName), proValue); break; } } return(parameters); }