Ejemplo n.º 1
0
 public SqlDumper(ISqlOutputStream stream, ISqlDialect dialect, SqlFormatProperties props)
 {
     m_stream             = stream;
     m_props              = props;
     m_dialect            = dialect;
     m_DDA                = dialect.CreateDataAdapter();
     m_formatterState.DDA = m_DDA;
 }
Ejemplo n.º 2
0
 public RecordToDbAdapter(ITableStructure recordFormat, ITableStructure targetTable, ISqlDialect targetDialect, DataFormatSettings formatSettings)
 {
     m_dstColTypes = new List <DbTypeBase>();
     foreach (var col in recordFormat.Columns)
     {
         m_dstColTypes.Add(targetTable.Columns[col.ColumnName].DataType);
     }
     m_dda        = targetDialect.CreateDataAdapter();
     m_outputConv = new BedValueConvertor(formatSettings);
 }
Ejemplo n.º 3
0
        // not very efective, better is to direct call DDA.GetSqlLiteral
        public static string GetSqlLiteral(this ISqlDialect dialect, object value)
        {
            var hld = new BedValueHolder();
            var dda = dialect.CreateDataAdapter();

            hld.ReadFrom(value);
            return(dda.GetSqlLiteral(hld));
            //if (value == DBNull.Value || value == null) return "NULL";
            //if (value.GetType().IsNumberType()) return dialect.EscapeNumber(value);
            //if (value is byte[]) return dialect.EscapeBinary((byte[])value);
            //if (value is DateTime) return dialect.EscapeDateTime((DateTime)value);
            //if (value is bool) return dialect.EscapeLogical((bool)value);
            //return dialect.QuoteString(Convert.ToString(value, CultureInfo.InvariantCulture));
        }
Ejemplo n.º 4
0
        private string CreateSearchCondition(ColumnDisplay disp, ISqlDialect dialect, IDmlfHandler handler)
        {
            if (disp == null)
            {
                disp = m_lastColumnDisplay;
            }
            if (disp == null)
            {
                return("1=1");
            }
            bool          was = false;
            StringBuilder res = new StringBuilder();
            //ITableStructure table = TableData.GetStructure(Perspective);
            var dda   = dialect.CreateDataAdapter();
            var spars = new FulltextSearchParams {
                ExactMatch = SearchExactMatch
            };

            foreach (var col in disp)
            {
                var cs = (IColumnStructure)col.ValueTag;
                if (cs == null)
                {
                    continue;
                }
                if (cs.DataType is DbTypeXml || cs.DataType is DbTypeBlob)
                {
                    continue;
                }
                if (SearchColumns != null && Array.IndexOf(SearchColumns, col.ValueRef.ToString()) < 0)
                {
                    continue;
                }
                if (was)
                {
                    res.Append(" OR ");
                }
                res.Append(dda.GetFulltextSearchExpr(col.ValueRef.Expr.ToSql(dialect, handler), SearchText, spars));
                //res.AppendFormat("{0} LIKE {1}", dialect.QuoteIdentifier(col.ColumnName), dialect.GetSqlLiteral("%" + SearchText + "%"));
                was = true;
            }
            if (!was)
            {
                res.Append("1=1");
            }
            return("(" + res.ToString() + ")");
        }
Ejemplo n.º 5
0
        public static string Format(ISqlDialect dialect, SqlFormatProperties props, SqlFormatterState state, string format, params object[] args)
        {
            IDialectDataAdapter dda = null;

            if (state != null)
            {
                dda = state.DDA;
            }
            if (dda == null)
            {
                dda = dialect.CreateDataAdapter();
            }

            int           argindex = 0;
            StringBuilder sb       = new StringBuilder();
            int           i        = 0;

            while (i < format.Length)
            {
                char c = format[i];
                switch (c)
                {
                case '^':     // SQL keyword
                {
                    i++;
                    SymbolPosition original = null;
                    if (format[i] == ':')
                    {
                        original = (SymbolPosition)args[argindex];
                        argindex++;
                        i++;
                    }
                    DumpSeparatorIfNeeded(sb, props, state, original);
                    while (i < format.Length && (Char.IsLetter(format, i) || format[i] == '_'))
                    {
                        sb.Append(GetCasedChar(format[i], props.SqlCommandCase));
                        i++;
                    }
                    DataDumped(state);
                }
                break;

                case '&':     // indentation & spacing
                {
                    i++;
                    c = format[i];
                    i++;
                    char level = '0';
                    if (c == '1' || c == '2' || c == '3' || c == '5')
                    {
                        level = c;
                        c     = format[i];
                        i++;
                    }
                    if (level != '0')
                    {
                        // indentation levels
                        if (props.IndentationLevel == SqlIndentationLevel.Original || props.IndentationLevel == SqlIndentationLevel.SingleLine)
                        {
                            if (c == 'n' || c == 's')
                            {
                                if (state != null)
                                {
                                    state.SeparatorNeeded = true;
                                }
                                else
                                {
                                    sb.Append(" ");
                                }
                            }
                            // when original indentation is used, don't use our separators
                            break;
                        }
                        bool valid = (props.IndentationLevel == SqlIndentationLevel.Compact && (level == '2' || level == '5')) ||
                                     (props.IndentationLevel == SqlIndentationLevel.Large && (level == '3' || level == '5'));
                        if (!valid)
                        {
                            break;         // mark is not for this indentation level
                        }
                    }
                    switch (c)
                    {
                    case '&':
                        sb.Append("&");
                        break;

                    case 'n':
                        if (state == null)
                        {
                            DumpEoln(sb, props, state);
                        }
                        else
                        {
                            state.LineFeedNeeded = true;
                        }
                        break;

                    case '>':
                        if (state != null)
                        {
                            state.IndentLevel++;
                        }
                        break;

                    case '<':
                        if (state != null)
                        {
                            state.IndentLevel--;
                        }
                        break;

                    case 's':
                        if (state != null)
                        {
                            state.SeparatorNeeded = true;
                        }
                        else
                        {
                            sb.Append(" ");
                        }
                        break;

                    default:
                        throw new InternalError("DAE-00041 Unknown & formatting instruction:" + c);
                    }
                }
                break;

                case '%':     // format parameter
                {
                    i++;
                    c = format[i];

                    if (c == '%')
                    {
                        sb.Append('%');
                        i++;
                    }
                    else if (c == ',')         // comma separated list
                    {
                        i++;
                        c = format[i];
                        bool ok = false;
                        if (args[argindex] is IEnumerable)
                        {
                            ok = true;
                        }
                        if (args[argindex] is IBedRecord && c == 'v')
                        {
                            ok = true;
                        }
                        if (!ok)
                        {
                            throw new InternalError("DAE-00042 List must be of type Enumerable");
                        }

                        bool was = false;
                        if (args[argindex] is IEnumerable)
                        {
                            foreach (object item in (IEnumerable)args[argindex])
                            {
                                if (was)
                                {
                                    sb.Append(", ");
                                }
                                WriteFormattedValue(dialect, props, sb, item, c, null, state, dda);
                                was = true;
                            }
                        }
                        else
                        {
                            var rec = (IBedRecord)args[argindex];
                            for (int x = 0; x < rec.FieldCount; x++)
                            {
                                if (was)
                                {
                                    sb.Append(", ");
                                }
                                rec.ReadValue(x);
                                sb.Append(GetSqlLiteral(props, dda, state, rec));
                                was = true;
                            }
                        }

                        argindex++;
                        i++;
                    }
                    else if (c == ':')
                    {
                        object orig = args[argindex];
                        argindex++;
                        i++;
                        c = format[i];
                        object arg = args[argindex];
                        argindex++;
                        i++;
                        WriteFormattedValue(dialect, props, sb, arg, c, orig, state, dda);
                    }
                    else
                    {
                        WriteFormattedValue(dialect, props, sb, args[argindex], c, null, state, dda);
                        argindex++;
                        i++;
                    }
                }
                break;

                default:
                {
                    if (Char.IsWhiteSpace(c))
                    {
                        if (state != null)
                        {
                            state.SeparatorNeeded = false;
                        }
                    }
                    else
                    {
                        DumpSeparatorIfNeeded(sb, props, state, null);
                    }
                    sb.Append(c);
                    i++;
                }
                break;
                }
            }
            return(sb.ToString());
        }
Ejemplo n.º 6
0
 public virtual IDialectDataAdapter CreateDataAdapter()
 {
     return(m_dialect.CreateDataAdapter());
 }