Esempio n. 1
0
 public DbRow(string table_name, params string[] keys)
     : this(table_name)
 {
     foreach (string key in keys)
     {
         properties[key] = new DbRowValue(true, true, false, true, table_name);
     }
 }
Esempio n. 2
0
        //this should be mostly for internal use see GetSqlQueryParameter
        public object GetDbValue(string column_name, object default_value)
        {
            if (properties.ContainsKey(column_name))
            {
                DbRowValue row_value = properties[column_name];

                return((row_value.value != null) ? row_value.value : ((row_value.allows_dbnull && default_value == null) ? DBNull.Value : default_value));
            }
            return(default_value);
        }
Esempio n. 3
0
        public void SetValue(string column_name, object value)
        {
            if (!properties.ContainsKey(column_name))
            {
                properties[column_name] = new DbRowValue();
            }

            properties[column_name].has_value_changed = true;
            properties[column_name].value             = value;
        }
Esempio n. 4
0
        public object GetValue(string column_name, object default_value)
        {
            if (properties.ContainsKey(column_name))
            {
                DbRowValue row_value = properties[column_name];

                return((row_value.value != null) ? row_value.value : default_value);
            }
            return(default_value);
        }
Esempio n. 5
0
        public DbRow(DbRow copy_schema, string new_schema_name)
            : this()
        {
            connection_string = copy_schema.connection_string;
            connection_name   = copy_schema.connection_name;
            table_name        = new_schema_name;
            is_managed        = copy_schema.is_managed;

            foreach (string key in copy_schema.properties.Keys)
            {
                properties[key] = new DbRowValue(copy_schema.properties[key]);
            }
        }
Esempio n. 6
0
        public void LoadValues(DataRow data_row)
        {
            foreach (DataColumn data_col in data_row.Table.Columns)
            {
                string current_col_name = data_col.ColumnName;

                if (!properties.ContainsKey(current_col_name))
                {
                    properties[current_col_name] = new DbRowValue(is_managed, false, null);
                }

                properties[current_col_name].value = Helper.read_database_value(data_row[current_col_name]);
            }
        }
Esempio n. 7
0
        public DbColumn <FieldType> NewColumn <FieldType>(string table_name, string name, bool is_key, bool is_read_only, bool is_managed, bool allows_dbnull, FieldType default_value)
        {
            is_managed = true;

            DbColumn <FieldType> new_field = new DbColumn <FieldType>(this, name, default_value);

            if (!properties.ContainsKey(name))
            {
                properties[name] = new DbRowValue(is_key, is_read_only, allows_dbnull, true, table_name);
                properties[name].default_value = default_value;
            }

            return(new_field);
        }
Esempio n. 8
0
        private void LoadValuesWithoutRead(SqlDataReader reader)
        {
            for (int i = 0; i < reader.FieldCount; i++)
            {
                string column = reader.GetName(i);

                //field wasn't added via NewColumn, most likely an unmanaged column
                if (!properties.ContainsKey(column))
                {
                    properties[column] = new DbRowValue(is_managed, false, null);
                }

                properties[column].value = Helper.read_database_value(reader.GetValue(i));
            }
        }
Esempio n. 9
0
        static public string GetSelectColumns(DbRow container, string container_column_prefix)
        {
            StringBuilder sb_columns = new StringBuilder();

            foreach (string key in container.properties.Keys)
            {
                DbRowValue current_field = container.properties[key];

                if (current_field.is_managed)
                {
                    if (sb_columns.Length > 0)
                    {
                        sb_columns.Append(',');
                    }

                    if (!string.IsNullOrEmpty(container_column_prefix))
                    {
                        sb_columns.Append(container_column_prefix);
                        sb_columns.Append('.');
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(current_field.table_name))
                        {
                            sb_columns.Append(current_field.table_name);
                            sb_columns.Append('.');
                        }
                        else if (!string.IsNullOrEmpty(container.table_name))
                        {
                            sb_columns.Append(container.table_name);
                            sb_columns.Append('.');
                        }
                    }

                    sb_columns.Append(key);
                }
            }

            return(sb_columns.ToString());
        }
Esempio n. 10
0
 public DbRowValue(DbRowValue copy_schema)
     : this(copy_schema.is_key, copy_schema.is_read_only, copy_schema.allows_dbnull, copy_schema.is_managed, copy_schema.table_name)
 {
 }
Esempio n. 11
0
        public static DbRow[] Select(DbRow container_schema, string container_column_prefix, string extra_select, SqlQueryParameter[] extra_params, int top, string from_clause, string where_clause, string order_clause, int start_row, int end_row)
        {
            bool is_paged = start_row > 0 && end_row > 0;

            StringBuilder sb_columns = new StringBuilder();

            if (top > 0 && !is_paged)
            {
                sb_columns.AppendFormat("TOP {0} ", top);
            }

            if (container_schema != null)
            {
                bool first_time = true;

                foreach (string key in container_schema.properties.Keys)
                {
                    DbRowValue current_field = container_schema.properties[key];

                    if (current_field.is_managed)
                    {
                        if (!first_time)
                        {
                            sb_columns.Append(',');
                        }
                        else
                        {
                            first_time = false;
                        }

                        if (!string.IsNullOrEmpty(container_column_prefix))
                        {
                            sb_columns.Append(container_column_prefix);
                            sb_columns.Append('.');
                        }
                        else
                        {
                            if (!string.IsNullOrEmpty(current_field.table_name))
                            {
                                sb_columns.Append(current_field.table_name);
                                sb_columns.Append('.');
                            }
                            else if (!string.IsNullOrEmpty(container_schema.table_name))
                            {
                                sb_columns.Append(container_schema.table_name);
                                sb_columns.Append('.');
                            }

                            sb_columns.Append(key);
                        }
                    }
                }
            }

            if (!string.IsNullOrEmpty(extra_select))
            {
                if (sb_columns.Length > 0)
                {
                    sb_columns.Append(',');
                }
                sb_columns.Append(extra_select);
            }

            if (!string.IsNullOrEmpty(order_clause))
            {
                order_clause = string.Format("ORDER BY {0}", order_clause);
            }

            string select_statement;

            if (is_paged)
            {
                select_statement = string.Format("SELECT * FROM (SELECT ROW_NUMBER() OVER ({0}) AS RowNumber, {1} FROM {2} WHERE {3}) AS PagedView WHERE RowNumber BETWEEN {4} AND {5}",
                                                 order_clause,
                                                 sb_columns.ToString(),
                                                 from_clause,
                                                 where_clause,
                                                 start_row,
                                                 end_row);
            }
            else
            {
                select_statement = string.Format("SELECT {0} FROM {1} WHERE {2} {3}", sb_columns.ToString(), from_clause, where_clause, order_clause);
            }

            return(Select(container_schema, select_statement, extra_params));
        }