예제 #1
0
        void IColumnMapping.ProcessMapping(int column, int rowNumber, ICdlRecord record, ICdlValueWriter writer, IShellContext context)
        {
            if (_value == null)
            {
                _value = new CdlValueHolder();
            }
            if (Expression != null && Value != null)
            {
                throw new Exception("DBSH-00004 MapValue: Both Expression and Value is set");
            }
            var childContext = context.CreateChildContext();

            if (Value != null)
            {
                CreateColumnValues(record, childContext);
                string value = childContext.Replace(Value);
                _value.ReadFrom(value);
                _value.WriteTo(writer);
            }
            if (Expression != null)
            {
                CreateColumnValues(record, childContext);
                object value = childContext.Evaluate(Expression);
                _value.ReadFrom(value);
                _value.WriteTo(writer);
            }
            if (Expression == null && Value == null)
            {
                _value.SetNull();
                _value.WriteTo(writer);
            }
        }
예제 #2
0
        public CdlRow AddRow(ICdlRecord record)
        {
            var row = new CdlRow(this, new ArrayDataRecord(record), CdlRowState.Unchanged, m_structure);

            Rows.AddInternal(row);
            return(row);
        }
예제 #3
0
            internal void SaveRecord(ICdlRecord rec)
            {
                long pos0 = Data.Length;

                CdlTool.SaveRecord(rec.FieldCount, rec, m_writer);
                Lengths.Add((int)(Data.Length - pos0));
            }
예제 #4
0
 public void PutRecord(ICdlRecord record)
 {
     object[] values = new object[record.FieldCount];
     record.GetValues(values);
     ICdlRecord copy = new ArrayDataRecord(Format, values);
     m_queue.Put(new Element { Record = copy });
 }
예제 #5
0
        public void Write(ICdlRecord row)
        {
            if (_insertSeparatorAfterRows.HasValue && _rowsAfterSeparator > _insertSeparatorAfterRows.Value)
            {
                _stream.Write("GO\n");
                _rowsAfterSeparator = 0;
            }
            var fmt = _factory.CreateLiteralFormatter();

            _stream.Write("INSERT INTO [TABLE_NAME] (");
            _stream.Write(row.GetFieldNames().Select(x => "[" + x + "]").CreateDelimitedText(", "));
            _stream.Write(") VALUES (");
            for (int i = 0; i < row.FieldCount; i++)
            {
                if (i > 0)
                {
                    _stream.Write(", ");
                }
                row.ReadValue(i);
                fmt.ReadFrom(row);
                _stream.Write(fmt.GetText());
            }
            _stream.Write(");\n");
            _rowsAfterSeparator++;
        }
예제 #6
0
        public void Write(ICdlRecord row)
        {
            WantTransaction();

            var sb = new StringBuilder();

            sb.AppendFormat("insert into {0} ({1}) values (", TABLE_NAME, ColumnsText);

            for (int i = 0; i < row.FieldCount; i++)
            {
                row.ReadValue(i);
                if (i > 0)
                {
                    sb.Append(",");
                }
                sb.Append((int)row.GetFieldType());
                sb.Append(",");
                string sqldata;
                StorageTool.GetValueAsSqlLiteral(row, out sqldata);
                sb.Append(sqldata);
            }
            sb.Append(")");

            using (var inscmd = _conn.CreateCommand())
            {
                inscmd.Transaction = _tran;
                inscmd.CommandText = sb.ToString().Replace("\0", "\\0");
                inscmd.ExecuteNonQuery();
                _rowCount++;
            }
        }
예제 #7
0
파일: CdlRow.cs 프로젝트: dbshell/dbshell
 internal CdlRow(CdlTable table, ICdlRecord original, CdlRowState initialState, TableInfo structure)
 {
     m_table = table;
     m_fields = new FieldRec[m_table.Structure.Columns.Count];
     m_original = original;
     m_structure = structure;
     RowState = initialState;
 }
예제 #8
0
 internal CdlRow(CdlTable table, ICdlRecord original, CdlRowState initialState, TableInfo structure)
 {
     m_table     = table;
     m_fields    = new FieldRec[m_table.Structure.Columns.Count];
     m_original  = original;
     m_structure = structure;
     RowState    = initialState;
 }
예제 #9
0
 public static string[] GetFieldNames(this ICdlRecord record)
 {
     string[] res = new string[record.FieldCount];
     for (int i = 0; i < res.Length; i++)
     {
         res[i] = record.GetName(i);
     }
     return(res);
 }
예제 #10
0
 public static object SafeGetValue(this ICdlRecord record, int ordinal)
 {
     if (ordinal < 0)
     {
         return(null);
     }
     record.ReadValue(ordinal);
     return(record.GetValue());
 }
예제 #11
0
 public static object[] GetValuesByCols(this ICdlRecord record, int[] cols)
 {
     object[] values = new object[cols.Length];
     for (int i = 0; i < cols.Length; i++)
     {
         values[i] = record.GetValue(cols[i]);
     }
     return(values);
 }
예제 #12
0
        public void PutRecord(ICdlRecord record)
        {
            object[] values = new object[record.FieldCount];
            record.GetValues(values);
            ICdlRecord copy = new ArrayDataRecord(Format, values);

            m_queue.Put(new Element {
                Record = copy
            });
        }
예제 #13
0
 private void CreateColumnValues(ICdlRecord record, IShellContext context)
 {
     if (NeedColumnValues)
     {
         context.CreateScope();
         for (int i = 0; i < record.FieldCount; i++)
         {
             context.SetVariable(record.GetName(i), record.GetValue(i));
         }
     }
 }
예제 #14
0
 public void Write(ICdlRecord row)
 {
     _orec.Clear();
     for (int i = 0; i < row.FieldCount; i++)
     {
         row.ReadValue(i);
         _formatter.ReadFrom(row);
         _orec[i] = _formatter.GetText();
     }
     _dbf.Write(_orec);
 }
예제 #15
0
 public void Write(ICdlRecord row)
 {
     var dataRow = new object[row.FieldCount];
     _rows.Add(dataRow);
     for (int i = 0; i < row.FieldCount; i++)
     {
         row.ReadValue(i);
         _formatter.ReadFrom(row);
         dataRow[i] = _formatter.GetText();
     }
 }
예제 #16
0
파일: MapValue.cs 프로젝트: dbshell/dbshell
 private void CreateColumnValues(ICdlRecord record, IShellContext context)
 {
     if (NeedColumnValues)
     {
         context.CreateScope();
         for (int i = 0; i < record.FieldCount; i++)
         {
             context.SetVariable(record.GetName(i), record.GetValue(i));
         }
     }
 }
예제 #17
0
        public void Write(ICdlRecord row)
        {
            var dataRow = new object[row.FieldCount];

            _rows.Add(dataRow);
            for (int i = 0; i < row.FieldCount; i++)
            {
                row.ReadValue(i);
                _formatter.ReadFrom(row);
                dataRow[i] = _formatter.GetText();
            }
        }
예제 #18
0
 public ArrayDataRecord(ICdlRecord record, int[] colindexes, TableInfo changedStructure)
 {
     if (colindexes.Length != changedStructure.Columns.Count) throw new InternalError("DBSH-00050 ArrayDataRecord(): colnames.count != colindexes.count");
     _values = new object[colindexes.Length];
     for (int i = 0; i < colindexes.Length; i++)
     {
         if (colindexes[i] >= 0)
         {
             _values[i] = record.GetValue(colindexes[i]);
         }
     }
     _structure = changedStructure;
 }
예제 #19
0
 public static object[] GetValuesByCols(this ICdlRecord record, DmlfColumnRef[] cols, DmlfResultFieldCollection result)
 {
     if (result == null)
     {
         return(record.GetValuesByCols(cols.GetNames()));
     }
     object[] values = new object[cols.Length];
     for (int i = 0; i < cols.Length; i++)
     {
         int index = result.GetColumnIndex(cols[i]);
         values[i] = record.GetValue(index);
     }
     return(values);
 }
예제 #20
0
 void ICdlWriter.Write(ICdlRecord row)
 {
     if (_dataRecord == null)
     {
         _dataRecord = new string[row.FieldCount];
     }
     for (int i = 0; i < _dataRecord.Length; i++)
     {
         row.ReadValue(i);
         _formatter.ReadFrom(row);
         _dataRecord[i] = _formatter.GetText();
     }
     WriteRow(_dataRecord);
 }
예제 #21
0
        public static void SaveRecord(int fldcount, ICdlRecord record, BinaryWriter stream)
        {
            var fw = new StreamValueWriter(stream);

            if (fldcount != record.FieldCount)
            {
                throw new InternalError("DBSH-00034 field count mitchmatch");
            }
            for (int i = 0; i < fldcount; i++)
            {
                record.ReadValue(i);
                fw.ReadFrom(record);
            }
        }
예제 #22
0
 public void Write(ICdlRecord row)
 {
     var fmt = _factory.CreateLiteralFormatter();
     _stream.Write("INSERT INTO [TABLE_NAME] (");
     _stream.Write(row.GetFieldNames().Select(x => "[" + x + "]").CreateDelimitedText(", "));
     _stream.Write(") VALUES (");
     for (int i = 0; i < row.FieldCount; i++)
     {
         if (i > 0) _stream.Write(", ");
         row.ReadValue(i);
         fmt.ReadFrom(row);
         _stream.Write(fmt.GetText());
     }
     _stream.Write(");\n");
 }
예제 #23
0
        public ICdlRecord AdaptRecord(ICdlRecord record)
        {
            var res = new ArrayDataRecord(record.Structure);
            for (int i = 0; i < Math.Min(res.FieldCount, record.FieldCount); i++)
            {
                var targetColumn = _columnMap.GetTargetColumnBySourceIndex(i);
                if (targetColumn == null) continue;

                record.ReadValue(i);
                res.SeekValue(i);

                _dda.AdaptValue(record, targetColumn.CommonType, res, _outputConv);
            }
            return res;
        }
예제 #24
0
        public void Write(ICdlRecord row)
        {
            if (_currentChunk == null)
            {
                _currentChunk = new Chunk();
            }

            _currentChunk.SaveRecord(row);

            if (_currentChunk.Count >= BUFFER_SIZE)
            {
                FlushChunk(_currentChunk);
                _currentChunk = null;
            }
        }
예제 #25
0
 public ArrayDataRecord(ICdlRecord record, int[] colindexes, TableInfo changedStructure)
 {
     if (colindexes.Length != changedStructure.Columns.Count)
     {
         throw new InternalError("DBSH-00050 ArrayDataRecord(): colnames.count != colindexes.count");
     }
     _values = new object[colindexes.Length];
     for (int i = 0; i < colindexes.Length; i++)
     {
         if (colindexes[i] >= 0)
         {
             _values[i] = record.GetValue(colindexes[i]);
         }
     }
     _structure = changedStructure;
 }
예제 #26
0
        public ICdlRecord AdaptRecord(ICdlRecord record)
        {
            var res = new ArrayDataRecord(record.Structure);

            for (int i = 0; i < Math.Min(res.FieldCount, record.FieldCount); i++)
            {
                var targetColumn = _columnMap.GetTargetColumnBySourceIndex(i);
                if (targetColumn == null)
                {
                    continue;
                }

                record.ReadValue(i);
                res.SeekValue(i);

                _dda.AdaptValue(record, targetColumn.CommonType, res, _outputConv);
            }
            return(res);
        }
예제 #27
0
 public ICdlRecord GetRecord()
 {
     try
     {
         Element res = m_queue.Get();
         if (res.IsEof)
         {
             throw new Exception("DBSH-00009 Eof reached");
         }
         ICdlRecord rec = res.Record;
         return(rec);
     }
     catch (QueueClosedError)
     {
         if (m_error != null)
         {
             throw new QueueClosedError("DBSH-00010", m_error);
         }
         throw new QueueClosedError("DBSH-00011");
     }
 }
예제 #28
0
        public void Write(ICdlRecord row)
        {
            _writer.WriteStartElement(_rowElementName ?? "Row");
            for (int i = 0; i < row.FieldCount; i++)
            {
                string name = row.GetName(i);
                row.ReadValue(i);
                _formatter.ReadFrom(row);
                string value = _formatter.GetText();

                if (_useAttributes)
                {
                    _writer.WriteAttributeString(name, value);
                }
                else
                {
                    _writer.WriteStartElement(name);
                    _writer.WriteString(value);
                    _writer.WriteEndElement();
                }
            }
            _writer.WriteEndElement();
        }
예제 #29
0
 public ArrayDataRecord(ICdlRecord record)
 {
     _values = new object[record.FieldCount];
     _structure = record.Structure;
     record.GetValues(_values);
 }
예제 #30
0
 void IColumnMapping.ProcessMapping(int column, int rowNumber, ICdlRecord record, ICdlValueWriter writer, IShellContext context)
 {
     record.ReadValue(record.GetOrdinal(Name));
     record.WriteTo(writer);
 }
예제 #31
0
 public void Write(ICdlRecord row)
 {
     _queue.PutRecord(row);
 }
예제 #32
0
 public static object[] GetValues(this ICdlRecord record)
 {
     object[] values = new object[record.FieldCount];
     record.GetValues(values);
     return(values);
 }
예제 #33
0
 public static object GetValue(this ICdlRecord record, string colName)
 {
     return(record.GetValue(record.GetOrdinal(colName)));
 }
예제 #34
0
 void IColumnMapping.ProcessMapping(int column, int rowNumber, ICdlRecord record, ICdlValueWriter writer, IShellContext context)
 {
     writer.SetNull();
 }
예제 #35
0
 public void Write(ICdlRecord row)
 {
     _bw.Write(false);
     CdlTool.SaveRecord(row.FieldCount, row, _bw);
 }
예제 #36
0
 public void Write(ICdlRecord row)
 {
     _queue.PutRecord(row);
 }
예제 #37
0
 public ArrayDataRecord(ICdlRecord record)
 {
     _values    = new object[record.FieldCount];
     _structure = record.Structure;
     record.GetValues(_values);
 }
예제 #38
0
 internal void SaveRecord(ICdlRecord rec)
 {
     long pos0 = Data.Length;
     CdlTool.SaveRecord(rec.FieldCount, rec, m_writer);
     Lengths.Add((int) (Data.Length - pos0));
 }
예제 #39
0
        public void Write(ICdlRecord row)
        {
            if (_currentChunk == null)
            {
                _currentChunk = new Chunk();
            }

            _currentChunk.SaveRecord(row);

            if (_currentChunk.Count >= BUFFER_SIZE)
            {
                FlushChunk(_currentChunk);
                _currentChunk = null;
            }
        }
예제 #40
0
 public void Write(ICdlRecord row)
 {
     _stream.Write("<tr>");
     for (int i = 0; i < row.FieldCount; i++)
     {
         row.ReadValue(i);
         _formatter.ReadFrom(row);
         string value = _formatter.GetText();
         _stream.WriteLine("<td>{0}</td>", HttpUtility.HtmlEncode(value));
     }
     _stream.Write("</tr>");
 }
예제 #41
0
 public DataRowModel(ICdlRecord record)
 {
     _record = record;
 }
예제 #42
0
 void IColumnMapping.ProcessMapping(int column, int rowNumber, ICdlRecord record, ICdlValueWriter writer, IShellContext context)
 {
     record.ReadValue(record.GetOrdinal(Name));
     record.WriteTo(writer);
 }
예제 #43
0
 void ICdlWriter.Write(ICdlRecord row)
 {
     if (_dataRecord == null)
     {
         _dataRecord = new string[row.FieldCount];
     }
     for (int i = 0; i < _dataRecord.Length; i++)
     {
         row.ReadValue(i);
         _formatter.ReadFrom(row);
         _dataRecord[i] = _formatter.GetText();
     }
     WriteRow(_dataRecord);
 }
예제 #44
0
파일: MapNull.cs 프로젝트: dbshell/dbshell
 void IColumnMapping.ProcessMapping(int column, int rowNumber, ICdlRecord record, ICdlValueWriter writer, IShellContext context)
 {
     writer.SetNull();
 }
예제 #45
0
 void IColumnMapping.ProcessMapping(int column, int rowNumber, ICdlRecord record, ICdlValueWriter writer, IShellContext context)
 {
     writer.SetInt32(StartFrom + rowNumber);
 }
예제 #46
0
        public void Write(ICdlRecord row)
        {
            WantTransaction();

            var sb = new StringBuilder();
            sb.AppendFormat("insert into {0} ({1}) values (", TABLE_NAME, ColumnsText);

            for (int i = 0; i < row.FieldCount; i++)
            {
                row.ReadValue(i);
                if (i > 0) sb.Append(",");
                sb.Append((int)row.GetFieldType());
                sb.Append(",");
                string sqldata;
                StorageTool.GetValueAsSqlLiteral(row, out sqldata);
                sb.Append(sqldata);
            }
            sb.Append(")");

            using (var inscmd = _conn.CreateCommand())
            {
                inscmd.Transaction = _tran;
                inscmd.CommandText = sb.ToString().Replace("\0", "\\0");
                inscmd.ExecuteNonQuery();
                _rowCount++;
            }
        }
예제 #47
0
 public static object GetValue(this ICdlRecord record, int ordinal)
 {
     record.ReadValue(ordinal);
     return(record.GetValue());
 }
예제 #48
0
 void IColumnMapping.ProcessMapping(int column, int rowNumber, ICdlRecord record, ICdlValueWriter writer, IShellContext context)
 {
     writer.SetInt32(StartFrom + rowNumber);
 }
예제 #49
0
 public void Write(ICdlRecord row)
 {
     _bw.Write(false);
     CdlTool.SaveRecord(row.FieldCount, row, _bw);
 }
예제 #50
0
 public DataRowModel(ICdlRecord record)
 {
     _record = record;
 }
예제 #51
0
파일: MapValue.cs 프로젝트: dbshell/dbshell
 void IColumnMapping.ProcessMapping(int column, int rowNumber, ICdlRecord record, ICdlValueWriter writer, IShellContext context)
 {
     if (_value == null)
     {
         _value = new CdlValueHolder();
     }
     if (Expression != null && Value != null)
     {
         throw new Exception("DBSH-00004 MapValue: Both Expression and Value is set");
     }
     var childContext = context.CreateChildContext();
     if (Value != null)
     {
         CreateColumnValues(record, childContext);
         string value = childContext.Replace(Value);
         _value.ReadFrom(value);
         _value.WriteTo(writer);
     }
     if (Expression != null)
     {
         CreateColumnValues(record, childContext);
         object value = childContext.Evaluate(Expression);
         _value.ReadFrom(value);
         _value.WriteTo(writer);
     }
     if (Expression == null && Value == null)
     {
         _value.SetNull();
         _value.WriteTo(writer);
     }
 }
예제 #52
0
파일: CdlTool.cs 프로젝트: dbshell/dbshell
 public static void SaveRecord(int fldcount, ICdlRecord record, BinaryWriter stream)
 {
     var fw = new StreamValueWriter(stream);
     if (fldcount != record.FieldCount) throw new InternalError("DBSH-00034 field count mitchmatch");
     for (int i = 0; i < fldcount; i++)
     {
         record.ReadValue(i);
         fw.ReadFrom(record);
     }
 }