Beispiel #1
0
 public static extern void DB_api_internal_set(HandleRef jarg1, BaseDatabase jarg2);
 // type 1 = xml?
 void Store(BaseDatabase db, string key, string text, int type)
 {
     if (!db.Exists (TableName, columnKey, key)) {
         db.InsertData (TableName, new string[3]{columnKey, columnValue, columnType}, new object[3] {key, text, type});
     } else {
         // we do not obther updating TYPE
         db.UpdateSpecificColumnData(TableName, new string[2]{columnKey, columnValue}, new object[2] {key, text}, columnKey, key);
     }
 }
 private void TestExistence(BaseDatabase db, string key, Func<Layout.AppearanceClass> Setup)
 {
     if (!db.Exists (TableName, columnKey, key)) {
         Layout.AppearanceClass default1 = Setup();
         //Setup();
         SaveAppearance (default1);
     }
 }
Beispiel #4
0
 public BaseTable(string name, string owner, BaseDatabase parent)
 {
     this.shortName = name;
     this.owner = owner;
     this.parent = parent;
 }
        static void ExportChildLayout(string GUID, string FileName, BaseDatabase MyDatabase)
        {
            List<string> children = MyDatabase.GetBackupRowAsString (dbConstants.table_name, dbConstants.PARENT_GUID, GUID, true);
            if (children != null && children.Count > 0) {
                for (int i = 0; i < children.Count; i++) {
                    WriteFile (String.Format ("{1}__child{0}.txt", i.ToString (), FileName), children [i]);

                }
            }
            // Nope: Was actually working *but* again the new notes are messed up. All Child Panels are suppose to have the PARENTGUID of the the Master Layout (the absolute parent)
            //			// now we need the GUIDS for each of these children layouts
            //			List<object[]> results = MyDatabase.GetValues(dbConstants.table_name, new string[1]{ dbConstants.GUID}, dbConstants.PARENT_GUID, GUID);
            //			if (results != null)
            //			{
            //				foreach (object[] result in results)
            //				{
            //					if (result.Length > 0)
            //					{
            //						string childGUID = result[0].ToString();
            //						//ExportChildLayout(childGUID
            //					}
            //				}
            //			}
        }
Beispiel #6
0
 internal QueueDatabase(BaseDatabase clone) : base(clone)
 {
 }
Beispiel #7
0
 internal RecnoDatabase(BaseDatabase clone) : base(clone)
 {
 }
Beispiel #8
0
        /*
         * Given this SQL...
         *
         *  SELECT e.name, d.name
         *  FROM employee e
         *      LEFT JOIN department d ON e.department_id=d.id
         *  WHERE e.name LIKE 'm%'
         *
         * An event on employee would be checked by running...
         *
         *  SELECT e.name, d.name
         *  FROM employee e
         *      LEFT JOIN department d ON e.department_id=d.id
         *  WHERE e.name LIKE 'm%' AND e.id='123'
         *
         * An event on department would be checked by running...
         *
         *  SELECT e.name, d.name
         *  FROM employee e
         *      LEFT JOIN department d ON e.department_id=d.id AND d.id='456'
         *  WHERE e.name LIKE 'm%'
         *
         */
        internal async Task <Dict[]> GetImpactedRecordsAsync(KeyValueDataEvent keyValueDataEvent)
        {
            if (!this.dynamicStatementFromRefByTableName.TryGetValue(keyValueDataEvent.name, out StatementFromRef selectedStatementFromRef))
            {
                return(null);
            }
            logger.Trace($"GetImpactedRecordsAsync():name={name}");

            StringBuilder newFromClause  = new StringBuilder();
            string        newWhereClause = this.selectStatement.whereClause;
            Dict          newVarsDict    = new Dict(this.varsDict);

            foreach (StatementFromRef statementFromRef in this.selectStatement.StatementFromRefs)
            {
                StringBuilder sb = new StringBuilder();
                if (statementFromRef == selectedStatementFromRef)
                {
                    Dict primaryKeyValues = BaseDatabase.ParseKeyValue(keyValueDataEvent.keyValue, this.dynamicViewSet.Database.TableByName[keyValueDataEvent.name].Indexes[0].FieldNames);

                    foreach (var fieldName in this.dynamicViewSet.Database.TableByName[keyValueDataEvent.name].Indexes[0].FieldNames)
                    {
                        logger.Trace($"GetImpactedRecordsAsync():tableName={statementFromRef.table.Name},fieldName={fieldName}");

                        string prefix;
                        if (this.selectStatement.StatementFromRefs.Length == 1)
                        {
                            prefix = "";
                        }
                        else if (!string.IsNullOrEmpty(statementFromRef.tableAlias))
                        {
                            prefix = $"{statementFromRef.tableAlias}.";
                        }
                        else
                        {
                            prefix = $"{statementFromRef.table.Name}.";
                        }
                        logger.Trace($"GetImpactedRecordsAsync():prefix={prefix}");

                        var paramName = $"__{fieldName}";
                        var condition = $"{prefix}{fieldName}=@{paramName}";
                        logger.Trace($"GetImpactedRecordsAsync():condition={condition}");

                        if (sb.Length > 0)
                        {
                            sb.Append(" AND ");
                        }
                        sb.Append(condition);

                        newVarsDict[paramName] = primaryKeyValues[fieldName];
                    }
                    logger.Trace($"GetImpactedRecordsAsync():newAndCondition={newWhereClause}");
                }

                // JoinType = None only happens on first table reference
                if (statementFromRef.joinType == JoinType.None)
                {
                    newFromClause.Append(statementFromRef.table.Name);
                    if (!string.IsNullOrEmpty(statementFromRef.tableAlias))
                    {
                        newFromClause.Append($" {statementFromRef.tableAlias}");
                    }

                    if (sb.Length > 0)
                    {
                        if (string.IsNullOrEmpty(newWhereClause))
                        {
                            newWhereClause = sb.ToString();
                        }
                        else
                        {
                            newWhereClause = $"({newWhereClause}) AND ({sb.ToString()})";
                        }
                    }
                }
                else
                {
                    newFromClause.Append($" {statementFromRef.joinType.ToString().ToUpper()} JOIN");
                    newFromClause.Append($" {statementFromRef.table.Name}");
                    if (!string.IsNullOrEmpty(statementFromRef.tableAlias))
                    {
                        newFromClause.Append($" {statementFromRef.tableAlias}");
                    }
                    newFromClause.Append($" ON");

                    if (sb.Length > 0)
                    {
                        newFromClause.Append($" ({statementFromRef.joinCondition}) AND ({sb.ToString()})");
                    }
                    else
                    {
                        newFromClause.Append($" {statementFromRef.joinCondition}");
                    }
                }
            }

            SelectStatement newStatement = new SelectStatement(this.dynamicViewSet.Database, this.selectStatement.selectClause, newFromClause.ToString(), newWhereClause.ToString(), null);

            return(await this.dynamicViewSet.Database.SelectRowsAsync(newStatement, newVarsDict));
        }
Beispiel #9
0
        static void Main(string[] args)
        {
            //Create Test Tree
            var mainTestNode = ObjectComparator.CreateTestNode(new List <TestResult>(), ObjectType.Root, "Root node");

            try
            {
                if (args.Length == 4 && args[2].ToLower() == "delete")
                {
                    // Read arguments
                    string       connectionString = args[0];
                    string       databaseType     = args[1].ToLower();
                    string       resultPath       = args[3];
                    DatabaseType dbType           = BaseDatabase.GetDatabaseType(databaseType);
                    _settings = new Settings(connectionString, resultPath, databaseType);
                    try
                    {
                        switch (dbType)
                        {
                        case DatabaseType.SqlServer:
                            var deploy            = new MsSqlDeploy();
                            var connStringBuilder = Settings.GetMsSqlStringBuilder(connectionString);
                            var dbName            = connStringBuilder.InitialCatalog;
                            connStringBuilder.Remove("Initial Catalog");
                            var connStringWithoutCatalog = connStringBuilder.ConnectionString;
                            deploy.DeleteDatabase(dbName, connStringWithoutCatalog, dbType);
                            break;

                        case DatabaseType.MySql:
                            var deploy1                   = new MySqlDeploy();
                            var connStringBuilder1        = Settings.GetMySqlStringBuilder(connectionString);
                            var dbName1                   = connStringBuilder1.Database;
                            var connStringWithoutCatalog1 = connStringBuilder1.ConnectionString;
                            deploy1.DeleteDatabase(dbName1, connStringWithoutCatalog1, dbType);
                            break;

                        default:
                            throw new ArgumentOutOfRangeException();
                        }
                    }
                    catch (ArgumentOutOfRangeException ex)
                    {
                        Logger.Error(ex, $"Unsupported database type {databaseType}");
                        Environment.Exit((int)ExitCodes.InvalidArguments);
                    }
                    catch (Exception ex)
                    {
                        Logger.Error(ex, $"Unexpected exception occured.");
                        Environment.Exit((int)ExitCodes.UnsupportedDbType);
                    }

                    Environment.Exit((int)ExitCodes.Success);
                }
                else if (args.Length == 4)
                {
                    Logger.Info("Running deploying script task.");
                    // Read arguments
                    string connectionString = args[0];


                    string       databaseType = args[1];
                    DatabaseType dbType       = BaseDatabase.GetDatabaseType(databaseType);

                    string pathToScript = args[2];
                    string resultPath   = args[3];

                    Logger.Debug($"Arguments passed \narg[0]:{connectionString} \narg[1]:{databaseType} \narg[2]:{pathToScript} \narg[3]:{resultPath}.");

                    _settings = new Settings(connectionString, resultPath, databaseType);
                    try
                    {
                        switch (dbType)
                        {
                        case DatabaseType.SqlServer:
                            var deploy            = new MsSqlDeploy();
                            var connStringBuilder = Settings.GetMsSqlStringBuilder(connectionString);
                            var dbName            = connStringBuilder.InitialCatalog;
                            connStringBuilder.Remove("Initial Catalog");
                            var connStringWithoutCatalog = connStringBuilder.ConnectionString;
                            deploy.DeployDatabase(mainTestNode, connectionString, dbName, connStringWithoutCatalog, dbType, pathToScript);
                            break;

                        case DatabaseType.MySql:
                            var deploy1            = new MySqlDeploy();
                            var connStringBuilder1 = Settings.GetMySqlStringBuilder(connectionString);
                            var dbName1            = connStringBuilder1.Database;
                            connStringBuilder1.Remove("Database");
                            var connStringWithoutCatalog1 = connStringBuilder1.ConnectionString;
                            deploy1.DeployDatabase(mainTestNode, connectionString, dbName1, connStringWithoutCatalog1, dbType, pathToScript);
                            break;

                        default:
                            throw new ArgumentOutOfRangeException();
                        }
                        Logger.Info("Task successful.");
                        Environment.Exit((int)ExitCodes.Success);
                    }
                    catch (ArgumentOutOfRangeException ex)
                    {
                        Logger.Error(ex, $"Unsupported database type {databaseType}");
                        Environment.Exit((int)ExitCodes.InvalidArguments);
                    }
                    catch (Exception ex)
                    {
                        Logger.Error(ex, "Unexpected exception occured.");
                        Environment.Exit((int)ExitCodes.UnexpectedError);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex,
                             $"Invalid input argument count [{args.Length}]. Exactly arguments 3 required.");
                Environment.Exit((int)ExitCodes.InvalidArguments);
            }
        }
Beispiel #10
0
        internal RecordDataEvent[] ProcessDataChange(DataEvent dataEvent, Dict[] preCommitImpactedRecords, Dict[] postCommitImpactedRecords)
        {
            logger.Trace($"ProcessDataChange():dataEvent={dataEvent},preCommitImpactedRecords.Length={preCommitImpactedRecords?.Length},postCommitImpactedRecords.Length={postCommitImpactedRecords?.Length}");
            if (!(dataEvent is KeyValueDataEvent keyValueDataEvent))
            {
                return(null);
            }

            if (!this.selectStatement.HasTableInFrom(keyValueDataEvent.name))
            {
                return(null);
            }

            List <RecordDataEvent> recordDataEvents = new List <RecordDataEvent>();
            var preCommitKeyValues  = preCommitImpactedRecords == null ? new object[] { } : preCommitImpactedRecords.Select(x => BaseDatabase.GetKeyValue(this.keyFieldNames, x)).ToArray();
            var postCommitKeyValues = postCommitImpactedRecords == null ? new object[] { } : postCommitImpactedRecords.Select(x => BaseDatabase.GetKeyValue(this.keyFieldNames, x)).ToArray();

            // Find updates and deletes
            for (int i = 0; i < preCommitKeyValues.Length; i++)
            {
                int postCommitIndex = Array.IndexOf(postCommitKeyValues, preCommitKeyValues[i]);
                if (postCommitIndex >= 0)
                {
                    if (!preCommitImpactedRecords[i].IsSame(postCommitImpactedRecords[postCommitIndex]))
                    {
                        recordDataEvents.Add(new RecordDataEvent(DataEventType.Update, this.name, preCommitKeyValues[i], postCommitImpactedRecords[postCommitIndex]));
                    }
                }
                else
                {
                    recordDataEvents.Add(new RecordDataEvent(DataEventType.Delete, this.name, preCommitKeyValues[i], preCommitImpactedRecords[i]));
                }
            }

            // Find inserts
            for (int i = 0; i < postCommitKeyValues.Length; i++)
            {
                int preCommitIndex = Array.IndexOf(preCommitKeyValues, postCommitKeyValues[i]);
                if (preCommitIndex == -1)
                {
                    recordDataEvents.Add(new RecordDataEvent(DataEventType.Insert, this.name, postCommitKeyValues[i], postCommitImpactedRecords[i]));
                }
            }
            logger.Trace($"ProcessDataChange():recordDataEvents={string.Join(",", recordDataEvents)}");
            return(recordDataEvents.ToArray());
        }
Beispiel #11
0
 internal HashDatabase(BaseDatabase clone) : base(clone)
 {
 }
Beispiel #12
0
        public IActionResult Index()
        {
            BaseDatabase baseDatabase = Helper.JsonHelper.GetDatabase();

            return(View(baseDatabase));
        }
Beispiel #13
0
 internal BTreeDatabase(BaseDatabase clone) : base(clone)
 {
 }
Beispiel #14
0
 internal HeapDatabase(BaseDatabase clone) : base(clone)
 {
 }