/// <summary>
        /// construct and execute sql to populate possible states table using those attribute table.
        /// </summary>
        /// <param name="tableName"></param>
        private List <string> PreparePossibleStatesTable(string tableName)
        {
            if (!underlineDatabase.CheckIsTableAlreadyExist(tableName + "_0"))
            {
                throw new Exception(tableName + "_0 table doesn't exist");
            }
            List <List <string> > colNamesList = new List <List <string> >();
            var getVariables      = string.Format("SELECT var,att0,p FROM {0}_0", tableName);
            var getVariblesResult = underlineDatabase.ExecuteSqlWithResult(getVariables);

            foreach (DataRow row in getVariblesResult.Rows)
            {
                var           variable        = row.Field <int>("var");
                var           tableNameString = row.Field <string>("att0");
                var           tableNames      = new List <string>(tableNameString.Split(','));
                var           p        = row.Field <double>("p");
                List <string> colNames = GeneratePossibleStates(tableName, variable, tableNames, p);
                colNamesList.Add(colNames);
            }

            if ((colNamesList.Count) > 1)
            {
                return(colNamesList[0]);
            }
            else
            {
                throw new Exception("inconsistency in attribute sizes of different tuples");
            }
        }
        /// <summary>
        /// its operation is described by google doc chapter 1 storage,
        /// if table already exist then ignore the create table operation
        /// just do the insert value
        /// </summary>
        /// <param name="query"></param>
        private void HandleInsertSqlQuery(SqlInsertQuery query)
        {
            // only check prime field table here, is it safe enough ?
            bool          isTableExist = underlineDatabase.CheckIsTableAlreadyExist(query.TableName + "_0");
            List <Object> attributes   = query.Attributes;

            int randomVariable = 1;

            if (!isTableExist)
            {
                // table creation operation here

                createAttributeTables(query, attributes);
                createPossibleStatesTable(query, attributes);
                createPossibleWorldsTable(query, attributes);
            }
            else
            {
                randomVariable = underlineDatabase.GetNextFreeVariableId(query.TableName);
                if (randomVariable <= 0)
                {
                    randomVariable = 1;
                }
            }

            // insert value into tables starting here
            InsertAttributeValue(query, attributes, randomVariable);
            PopulatePossibleStatesTable(query, randomVariable);
            PopulatePossibleWorlds(query, randomVariable);
        }
Exemple #3
0
        private void WriteResultToAnswerTable(int worldNo, DataTable content, double probability)
        {
            DataTable answerTable = new DataTable();

            answerTable.Columns.Add(new DataColumn("worldNo", typeof(int)));
            var attCols  = content.Columns;
            var colNames = new List <string>();

            foreach (DataColumn col in attCols)
            {
                answerTable.Columns.Add(col.ColumnName, typeof(string));
                colNames.Add(col.ColumnName);
            }
            answerTable.Columns.Add(new DataColumn("p", typeof(double)));

            var distinctRows = content.DefaultView.ToTable(true, colNames.ToArray());

            foreach (DataRow row in distinctRows.Rows)
            {
                var newRow = answerTable.NewRow();
                newRow.SetField("worldNo", worldNo);
                newRow.SetField("p", probability);

                foreach (DataColumn column in content.Columns)
                {
                    var columnName = column.ColumnName;
                    newRow.SetField(columnName, row.Field <string>(columnName));
                }
                answerTable.Rows.Add(newRow);
            }
            if (underlineDatabase.CheckIsTableAlreadyExist(answerTableName))
            {
                underlineDatabase.WriteTableBacktoDatabase(answerTableName, answerTable);
            }
            else
            {
                underlineDatabase.CreateNewTableWithDataTable(answerTableName, answerTable);
            }
        }