Exemple #1
0
        public void InsertData(string schemaName, string objectName, string[] columns, Object[] data, ColumnDefaults defaults)
        {
            if (data.Length == 0)
            {
                throw new NoRowsToInsert();
            }

            var columnsWithDefaultsAdded = ColumnsWithDefaultsAdded(columns, defaults);

            var sqlColumns = SqlColumns(columnsWithDefaultsAdded);

            foreach (Object[] row in data)
            {
                var newRow = CombineRowDataWithDefaults(row, columnsWithDefaultsAdded);

                InsertRow(schemaName, objectName, sqlColumns, newRow);
            }
        }
Exemple #2
0
        private Dictionary <string, object> ColumnsWithDefaultsAdded(Object[] columns, ColumnDefaults defaults)
        {
            var combinedColumns = new Dictionary <string, object>();

            if (columns != null)
            {
                foreach (string c in columns)
                {
                    combinedColumns.Add(c, "ColumnInData");
                }
            }
            foreach (KeyValuePair <string, object> d in defaults)
            {
                if (combinedColumns.ContainsKey(d.Key))
                {
                    combinedColumns[d.Key] = d.Value;
                }
                else
                {
                    combinedColumns.Add(d.Key, d.Value);
                }
            }

            if (combinedColumns.Count == 0)
            {
                throw new NoColumnsToInsert();
            }

            return(combinedColumns);
        }