public bool OpenFuzzyDatabase(FdbEntity fdb) { try { SqliteConnection connection = new SqliteConnection(fdb.ConnString); DataSet ds = new DataSet(); ds.Tables.Add(connection.GetDataTable("SELECT * FROM SystemScheme", "system_scheme"));//Table [0] ds.Tables.Add(connection.GetDataTable("SELECT * FROM SystemRelation", "system_relation"));//Table [1] ds.Tables.Add(connection.GetDataTable("SELECT * FROM SystemAttribute", "system_attribute"));//Table [2] ds.Tables.Add(connection.GetDataTable("SELECT * FROM SystemQuery", "system_query"));//Table [3] ///Load Schemes//////////////////////////////////////////////////////////////////////////////////////// foreach (DataRow row in ds.Tables["system_scheme"].Rows) { String schemeName = row[1].ToString(); FzSchemeEntity tmpScheme = new FzSchemeEntity(schemeName); DataTable tmpDt = new DataTable(); tmpDt = connection.GetDataTable("SELECT * FROM SystemAttribute Where SchemeID=" + Convert.ToInt16(row[0])); if (tmpDt != null) { foreach (DataRow item in tmpDt.Rows) { Boolean primaryKey = Convert.ToBoolean(item[1]); String attributeName = Convert.ToString(item[2]); String typeName = Convert.ToString(item[3]); String domain = Convert.ToString(item[4]); String description = Convert.ToString(item[5]); FzDataTypeEntity tmpDataType = new FzDataTypeEntity(typeName, domain); FzAttributeEntity tmpAttribute = new FzAttributeEntity(primaryKey, attributeName, tmpDataType, description); tmpScheme.Attributes.Add(tmpAttribute); } fdb.Schemes.Add(tmpScheme); } } ///Load Relations////////////////////////////////////////////////////////////////////////////////////////// foreach (DataRow row in ds.Tables["system_relation"].Rows) { String relationName = row[1].ToString(); int schemeID = Convert.ToInt16(row[2]);//To get scheme is referenced String schemeName = connection.GetValueField("SELECT SchemeName FROM SystemScheme WHERE ID=" + schemeID).ToString(); DataTable tmpDt = new DataTable(); tmpDt = connection.GetDataTable("SELECT * FROM " + relationName); FzRelationEntity tmpRelation = new FzRelationEntity(relationName);//Relation only content relation name, but scheme referenced and list tuples is null tmpRelation.Scheme = FzSchemeDAL.GetSchemeByName(schemeName, fdb);//Assign scheme referenced to relation, but tuples is null int nColumns = tmpRelation.Scheme.Attributes.Count;//Get number columns of per row if (tmpDt != null)// { foreach (DataRow tupleRow in tmpDt.Rows) { List<Object> objs = new List<object>(); for (int i = 0; i < nColumns; i++)//Add values on per row from tupleRow[i] { //values += tupleRow[i].ToString(); objs.Add(tupleRow[i]); } FzTupleEntity tmpTuple = new FzTupleEntity() { ValuesOnPerRow = objs }; tmpRelation.Tuples.Add(tmpTuple); } } fdb.Relations.Add(tmpRelation); } ///Load Queries//////////////////////////////////////////////////////////////////////////////////////////// foreach (DataRow row in ds.Tables["system_query"].Rows) { FzQueryEntity tmpQuery = new FzQueryEntity(row[1].ToString(), row[2].ToString()); fdb.Queries.Add(tmpQuery); } return true; } catch (SQLiteException ex) { throw new Exception("ERROR:\n" + ex.Message); //return false; } }
public void DropFuzzyDatabase(FdbEntity fdb) { try { SqliteConnection connection = new SqliteConnection(fdb.ConnString); DataSet ds = new DataSet(); ds.Tables.Add(connection.GetDataTable("SELECT * FROM SystemScheme", "system_scheme")); ds.Tables.Add(connection.GetDataTable("SELECT * FROM SystemRelation", "system_relation")); ds.Tables.Add(connection.GetDataTable("SELECT * FROM SystemAttribute", "system_attribute")); ds.Tables.Add(connection.GetDataTable("SELECT * FROM SystemQuery", "system_query")); foreach (DataRow row in ds.Tables["system_relation"].Rows) { String relationname = row[1].ToString(); if (!connection.DropTable(relationname)) { throw new Exception(connection.ErrorMessage); } } if (!connection.Update("DELETE FROM SystemScheme")) { throw new Exception(connection.ErrorMessage); } if (!connection.Update("DELETE FROM SystemRelation")) { throw new Exception(connection.ErrorMessage); } if (!connection.Update("DELETE FROM SystemAttribute")) { throw new Exception(connection.ErrorMessage); } if (!connection.Update("DELETE FROM SystemQuery")) { throw new Exception(connection.ErrorMessage); } connection.CloseConnect(); } catch (Exception ex) { throw new Exception("ERROR:\n" + ex.Message); } }