private string FormatDbObjectStr(DbObjectInfo obj)
            {
                ByteConverter.ConvToNearsetUnit(obj.bytes, ByteUnit.B, out long newNum, out ByteUnit newUnit);

                switch (obj.forms)
                {
                case DDBString.TableForm:
                    return(string.Format("{0} {1}x{2} [{3}{4}]", obj.name, obj.rows, obj.columns, newNum, newUnit));

                case DDBString.DictionaryForm:
                case DDBString.SetForm:
                    return(string.Format("{0}<{1}> {2} keys [{3}{4}]", obj.name, obj.type.ToLower(), obj.rows, newNum, newUnit));

                case DDBString.ScalarForm:
                case DDBString.PairForm:
                    return(string.Format("{0}<{1}>", obj.name, obj.type.ToLower()));

                case DDBString.VectorForm:
                    return(string.Format("{0}<{1}> {2} rows [{3}{4}]", obj.name, obj.type.ToLower(), obj.rows, newNum, newUnit));

                case DDBString.MatrixForm:
                    return(string.Format("{0}<{1}> {2}x{3} [{4}{5}]", obj.name, obj.type.ToLower(), obj.rows, obj.columns, newNum, newUnit));
                }

                if (obj.rows != 1 || obj.columns != 1)
                {
                    return(string.Format("{0}[{1}x{2}]", obj.name, obj.rows, obj.columns));
                }
                return(obj.name);
            }
Exemplo n.º 2
0
        private void AddSelectedToDest()
        {
            if (grdSource.SelectedRows.Count == 0)
            {
                return;
            }


            DbObjectInfo sel = null;

            foreach (DataGridViewRow row in grdSource.SelectedRows)
            {
                sel = new DbObjectInfo();

                sel.Name    = (string)row.Cells[colSourceName.Name].Value;
                sel.ObjType = (string)row.Cells[colSourceType.Name].Value;
                sel.Owner   = (string)row.Cells[colSourceOwner.Name].Value;
                if (_selectedObjects.Contains(sel))
                {
                    continue;
                }

                _selectedObjects.Add(sel);
            }

            bsDest.ResetBindings(false);
        }
Exemplo n.º 3
0
        private void SetLastUpdater(object obj, string userId)
        {
            DbObjectInfo dbObjectInfo = DbObjectTools.GetDbObjectInfo(obj.GetType());

            if (DbObjectTools.GetDynamicPropertyInfo(obj.GetType(), "LastUpdateUserId") != null)
            {
                ((DbObject)obj).SetValue <string>("LastUpdateUserId", userId);
            }
        }
Exemplo n.º 4
0
        private async Task <string> ObjItemExportAsync(string script, Config cfg)
        {
            DbObjectInfo info = CheckObjectSelectedItemVariable();

            TableResult result = await RunScriptAndFetchResultAsDataTableAsync(conn, info.name);

            RenameDataTableColumnBasedValueName(result, info.name);

            return(ExportTableAndGenOutputLog(result.table, result.columnSrcType, cfg, null));
        }
Exemplo n.º 5
0
        public void PrepareObjectFromContent(string content)
        {
            _selectedObjects.Clear();
            bsDest.DataSource = null;

            string          newContent = content.Replace("\r", String.Empty);
            string          pattern    = @"(?<ObjType>SPR|FNC|TBL|TRG|VW)\s*\=\s*\[{0,1}\s*(?<Schema>\w*)\s*\]{0,1}\s*\.{1}\s*\[{0,1}\s*(?<ObjName>\w*)\s*\]{0,1}\s*";
            MatchCollection matches    = Regex.Matches(newContent, pattern, RegexOptions.IgnoreCase);

            string       objType = String.Empty;
            string       schema  = String.Empty;
            string       objName = String.Empty;
            DbObjectInfo sel     = null;

            foreach (Match m in matches)
            {
                if (!m.Success)
                {
                    continue;
                }

                objType = String.Empty;
                schema  = String.Empty;
                objName = String.Empty;

                objType = m.Groups["ObjType"].Value;
                schema  = m.Groups["Schema"].Value;
                objName = m.Groups["ObjName"].Value;

                if (String.IsNullOrEmpty(objType) || String.IsNullOrEmpty(schema) || String.IsNullOrEmpty(objName))
                {
                    continue;
                }

                objType = DbObjectListUtils.DecodeObjectType(objType);
                if (!IsObjectTypeValid(objType))
                {
                    continue;
                }

                if (string.IsNullOrEmpty(objType))
                {
                    continue;
                }

                sel         = new DbObjectInfo();
                sel.Name    = objName;
                sel.Owner   = schema;
                sel.ObjType = objType;

                _selectedObjects.Add(sel);
            }

            bsDest.DataSource = _selectedObjects;
        }
        public static List <string> GetModelNames(Module module)
        {
            List <string> list = new List <string>();

            foreach (Type type in module.GetTypes())
            {
                DbObjectInfo dbObjectInfo = DbObjectTools.GetDbObjectInfo(type);
                list.Add(dbObjectInfo.TableName);
            }
            return(list);
        }
Exemplo n.º 7
0
            public override bool Equals(object obj)
            {
                DbObjectInfo inObj = obj as DbObjectInfo;

                if (inObj == null)
                {
                    return(false);
                }

                return(Name.Equals(inObj.Name, StringComparison.InvariantCulture) &&
                       ObjType.Equals(inObj.ObjType, StringComparison.InvariantCulture) &&
                       Owner.Equals(inObj.Owner, StringComparison.InvariantCulture));
            }
Exemplo n.º 8
0
        private DbObjectInfo CheckObjectSelectedItemVariable()
        {
            ObjectViewItem item = ObjectView.SelectedItem as ObjectViewItem;

            if (item == null)
            {
                throw new ArgumentNullException("Invalid Variable");
            }
            DbObjectInfo info = item.Tag as DbObjectInfo;

            if (info == null)
            {
                throw new ArgumentException("Invalid Variable");
            }
            return(info);
        }
Exemplo n.º 9
0
        public async Task <ProcedureInfo> ReadSpInfoAsync(string spFullName, IContext context, IDictionary <string, object> session = null)
        {
            using (var connection = new SqlConnection(m_connectionString))
                using (var command = new SqlCommand(spFullName, connection))
                {
                    command.CommandType = CommandType.StoredProcedure;
                    await connection.OpenAsync();

                    SqlCommandBuilder.DeriveParameters(command);

                    var sp = new ProcedureInfo(spFullName);

                    foreach (SqlParameter parameter in command.Parameters)
                    {
                        var dataType = m_sqlDbTypeInfo.GetDataType(parameter.SqlDbType);
                        if (dataType == typeof(string))
                        {
                            parameter.Value = "a";
                        }
                        var parameterInfo = new SqlParameterInfo(parameter, dataType);
                        sp.AddParameter(parameterInfo);
                        if (false != string.IsNullOrWhiteSpace(parameter.TypeName))
                        {
                            continue;
                        }

                        string tableTypeName = new DbObjectInfo(parameter.TypeName).FullName;
                        parameter.TypeName = tableTypeName;
                        var tableTypeSchema = GetFromSession <DataTable>(tableTypeName, session);
                        if (!ReferenceEquals(tableTypeSchema, null))
                        {
                            parameter.Value = tableTypeSchema.Clone();
                            parameterInfo.TableTypeSchema = tableTypeSchema;
                            continue;
                        }

                        using (var loadTableValueParameterSchemaCmd = new SqlCommand())
                        {
                            loadTableValueParameterSchemaCmd.Connection  = connection;
                            loadTableValueParameterSchemaCmd.CommandText =
                                $@"
                            DECLARE @t AS {tableTypeName}
                            SELECT * FROM @t
                        ";
                            using (var reader = await loadTableValueParameterSchemaCmd.ExecuteReaderAsync(CommandBehavior.SchemaOnly | CommandBehavior.KeyInfo))
                            {
                                tableTypeSchema = new DataTable(tableTypeName);
                                tableTypeSchema.Load(reader);
                                AddToSession(tableTypeName, tableTypeSchema, session);
                                parameter.Value = tableTypeSchema.Clone();
                                parameterInfo.TableTypeSchema = tableTypeSchema;
                            }
                        }
                    }

                    if (context?.IgnoreQueryResult(spFullName) == true)
                    {
                        return(sp);
                    }

                    try
                    {
                        DataSet schema  = new DataSet();
                        var     adapter = new SqlDataAdapter(command);
                        adapter.FillSchema(schema, SchemaType.Source);
                        for (int i = 0; i < schema.Tables.Count; ++i)
                        {
                            schema.Tables[i].TableName = $"{spFullName} > result {i}";
                        }

                        sp.AddResultSchemas(schema.Tables.OfType <DataTable>());
                    }
                    catch (SqlException ex)
                    {
                        var message = new StringBuilder($"Could not retrieve the {spFullName} query result information.");
                        if (ex.Message.Contains("Invalid object name '#"))
                        {
                            var procedureObj = new Mapping.Procedure();
                            var flagName     = nameof(procedureObj.IgnoreQueryResult);
                            message.Append($" If typed query result is required, avoid using temporary table(s) in the {spFullName} procedure code.");
                            message.Append($" Otherwise, to suppress this message, mark the procedure with the {flagName} attribute in the mapping.");
                            m_diagnosticsCallback.Warning(message.ToString());
                        }
                        else
                        {
                            message.Append($" Error: {ex.Message}");
                            m_diagnosticsCallback.Error(message.ToString());
                        }
                    }

                    return(sp);
                }
        }