/// <summary> Get the count of rows of the table</summary> private static int GetRowsCount(Type s) { int count = -1; String tableName = StructOpt.GetStructureName(s); String sql = string.Format("SELECT COUNT(*) FROM {0}", tableName); try { if (conn.State == ConnectionState.Closed) { conn.Open(); } using (SqliteCommand cmd = new SqliteCommand()) { cmd.Connection = PreKeyring.conn; cmd.CommandText = sql; SqliteDataReader reader = cmd.ExecuteReader(); reader.Read(); count = reader.GetInt32(0); reader.Close(); } } catch (System.Exception ex) { Console.WriteLine(ex.Message); return(-1); } return(count); }
private static String SQL_CreateTable(Type s) { String sql = "CREATE TABLE " + StructOpt.GetStructureName(s) + "("; Dictionary <String, int> fields = StructOpt.GetFieldInfo(s); Dictionary <String, int> .Enumerator enumerator = fields.GetEnumerator(); while (enumerator.MoveNext()) { KeyValuePair <String, int> field = enumerator.Current; sql += string.Format("{0} varchar({1}),", field.Key, field.Value); } // this will fail if there are no fields but thats not normally happening return(sql.Substring(0, sql.Length - 1) + ")"); }