Пример #1
0
        internal virtual DbColumnInformation GetDbColumnInformation(string tablename, string columnname, bool CaseSensivity)
        {
            DbColumnInformation res = new DbColumnInformation();

            res.MaxLength      = 50;
            res.IsNullable     = true;
            res.AdditionalInfo = "default";

            return(res);
        }
Пример #2
0
        internal override DbColumnInformation GetDbColumnInformation(string tablename, string columnname, bool CaseSensivity)
        {
            DbColumnInformation res = new DbColumnInformation();

            string sql = "";

            if (!CaseSensivity)
            {
                sql = string.Format("select max(length({0})) from {1}", columnname, tablename);
            }
            else
            {
                sql = string.Format("select max(length({0}{1}{2})) from {0}{3}{2}", _open_bracket, columnname, _close_bracket, tablename);
            }
            var res2 = ExecuteScalarCommand(CreateCommand(sql).ExecuteScalar);

            if (res2 != null && res2 != DBNull.Value)
            {
                var mlen = Convert.ToInt32(res2);
                res.MaxLength = (mlen > 0 ? mlen : 50);
            }

            _DR = ExecuteDataReader(CreateCommand(string.Format("pragma table_info({0})", tablename)).ExecuteReader);
            while (_DR.Read())
            {
                if (CaseSensivity)
                {
                    if (_DR["name"].ToString() == columnname)
                    {
                        res.IsNullable = !Convert.ToBoolean(_DR["notnull"]);
                        if (_DR["dflt_value"] != DBNull.Value)
                        {
                            res.DefaultValue = _DR["dflt_value"];
                        }
                    }
                }
                else
                {
                    if (_DR["name"].ToString().ToLower() == columnname.ToLower())
                    {
                        res.IsNullable = !Convert.ToBoolean(_DR["notnull"]);
                        if (_DR["dflt_value"] != DBNull.Value)
                        {
                            res.DefaultValue = _DR["dflt_value"];
                        }
                    }
                }
            }

            _DR.Close();

            return(res);
        }
Пример #3
0
        internal override DbColumnInformation GetDbColumnInformation(string tablename, string columnname, bool CaseSensivity)
        {
            DbColumnInformation res = base.GetDbColumnInformation(tablename, columnname, CaseSensivity);
            string sql = "";

            if (!CaseSensivity)
            {
                sql = "select * from information_schema.columns where lower(table_name)=lower('{0}') and lower(column_name)=lower('{1}')";
                if (!string.IsNullOrEmpty(_owner))
                {
                    sql += " and lower(table_schema)=lower('{2}')";
                }
            }
            else
            {
                sql = "select * from information_schema.columns where table_name='{0}' and column_name='{1}'";
                if (!string.IsNullOrEmpty(_owner))
                {
                    sql += " and table_schema='{2}'";
                }
            }

            if (string.IsNullOrEmpty(_owner))
            {
                sql = string.Format(sql, tablename, columnname);
            }
            else
            {
                sql = string.Format(sql, tablename, columnname, _owner);
            }

            _DR = ExecuteDataReader(CreateCommand(sql).ExecuteReader);
            while (_DR.Read())
            {
                if (_DR["column_default"] != null && _DR["column_default"] != DBNull.Value)
                {
                    res.DefaultValue = _DR["column_default"];
                }
                break;
            }
            _DR.Close();

            return(res);
        }
Пример #4
0
        internal override DbColumnInformation GetDbColumnInformation(string tablename, string columnname, bool CaseSensivity)
        {
            DbColumnInformation res = new DbColumnInformation();

            string sql = "";
            if (CaseSensivity)
            {
                sql = string.Format("select is_nullable,max_length,precision,scale, dc.definition,c.system_type_id "
                    + "from sys.tables t inner join sys.columns c on c.object_id=t.object_id  "
                    + "left outer join sys.default_constraints dc on dc.parent_object_id=c.object_id and c.column_id=dc.parent_column_id "
                    + "where t.name='{0}' and c.name='{1}'"
                    , tablename, columnname);
            }
            else
                sql = string.Format("select is_nullable,max_length,precision,scale, dc.definition,c.system_type_id "
                    + "from sys.tables t inner join sys.columns c on c.object_id=t.object_id  "
                    + "left outer join sys.default_constraints dc on dc.parent_object_id=c.object_id and c.column_id=dc.parent_column_id "
                    + "where lower(t.name)=lower('{0}') and lower(c.name)=lower('{1}')"
                    , tablename, columnname);

            _DR = ExecuteDataReader(CreateCommand(sql).ExecuteReader);

            while (_DR.Read())
            {
                res.IsNullable = (bool)_DR["is_nullable"];
                res.MaxLength = Convert.ToInt32(_DR["max_length"]);
                res.Precision = Convert.ToInt32(_DR["precision"]);
                res.Sacale = Convert.ToInt32(_DR["scale"]);
                if (_DR["definition"] != DBNull.Value)
                {
                    res.DefaultValue = _DR["definition"];
                    res.DefaultValue = DefValuePostProcessing(res.DefaultValue);
                }
                else
                    res.DefaultValue = null;

                if (_DR["system_type_id"] != null && _DR["system_type_id"] != DBNull.Value)
                {
                    int coltype = Convert.ToInt32(_DR["system_type_id"]);
                    if (coltype == 35)
                        res.MaxLength = 0;
                }

                break;
            }

            _DR.Close();

            /*var result = ExecuteScalarCommand(CreateCommand(sql).ExecuteScalar);
            if (result != null && result != DBNull.Value)
                res.MaxLength = Convert.ToInt32(result);*/

            return res;
        }
Пример #5
0
        internal override DbColumnInformation GetDbColumnInformation(string tablename, string columnname, bool CaseSensivity)
        {
            DbColumnInformation res = new DbColumnInformation();

            string sql = "";
            if (CaseSensivity)
            {
                sql = "select TABLE_NAME,COLUMN_NAME,DATA_TYPE,DATA_LENGTH, "
                + "data_precision,data_scale,NULLABLE,DATA_DEFAULT "
                + " from all_tab_columns "
                + "where  "
                + "table_name='{0}' and column_name='{1}'";
                if (!string.IsNullOrEmpty(_owner))
                    sql += " and owner='{2}'";
            }
            else
            {
                sql = "select TABLE_NAME,COLUMN_NAME,DATA_TYPE,DATA_LENGTH, "
                + "data_precision,data_scale,NULLABLE,DATA_DEFAULT "
                + " from all_tab_columns "
                + "where  "
                + "upper(table_name)=upper('{0}') and upper(column_name)=upper('{1}')";
                if (!string.IsNullOrEmpty(_owner))
                    sql += " and upper(owner)=upper('{2}')";
            }

            if (string.IsNullOrEmpty(_owner))
                sql = string.Format(sql, tablename, columnname);
            else
                sql = string.Format(sql, tablename, columnname,_owner);

            _DR = ExecuteDataReader(CreateCommand(sql).ExecuteReader);

            while (_DR.Read())
            {
                if (!string.IsNullOrEmpty(_DR["nullable"].ToString()))
                {
                    if (_DR["nullable"].ToString().ToUpper() == "Y")
                        res.IsNullable = true;
                    if (_DR["nullable"].ToString().ToUpper() == "N")
                        res.IsNullable = false;
                }
                if (_DR["data_length"] != DBNull.Value)
                    res.MaxLength = Convert.ToInt32(_DR["data_length"]);
                if (_DR["data_precision"] != DBNull.Value)
                    res.Precision = Convert.ToInt32(_DR["data_precision"]);
                if (_DR["data_scale"] != DBNull.Value)
                    res.Sacale = Convert.ToInt32(_DR["data_scale"]);

                if (_DR["DATA_DEFAULT"] != DBNull.Value)
                {
                    res.DefaultValue = _DR["DATA_DEFAULT"];
                    //res.DefaultValue = DefValuePostProcessing(res.DefaultValue);
                }
                else
                    res.DefaultValue = null;

                break;
            }

            _DR.Close();

            return res;
        }
Пример #6
0
        internal override DbColumnInformation GetDbColumnInformation(string tablename, string columnname, bool CaseSensivity)
        {
            DbColumnInformation res = new DbColumnInformation();

            string sql = "";

            if (CaseSensivity)
            {
                sql = "select TABLE_NAME,COLUMN_NAME,DATA_TYPE,DATA_LENGTH, "
                      + "data_precision,data_scale,NULLABLE,DATA_DEFAULT "
                      + " from all_tab_columns "
                      + "where  "
                      + "table_name='{0}' and column_name='{1}'";
                if (!string.IsNullOrEmpty(_owner))
                {
                    sql += " and owner='{2}'";
                }
            }
            else
            {
                sql = "select TABLE_NAME,COLUMN_NAME,DATA_TYPE,DATA_LENGTH, "
                      + "data_precision,data_scale,NULLABLE,DATA_DEFAULT "
                      + " from all_tab_columns "
                      + "where  "
                      + "upper(table_name)=upper('{0}') and upper(column_name)=upper('{1}')";
                if (!string.IsNullOrEmpty(_owner))
                {
                    sql += " and upper(owner)=upper('{2}')";
                }
            }

            if (string.IsNullOrEmpty(_owner))
            {
                sql = string.Format(sql, tablename, columnname);
            }
            else
            {
                sql = string.Format(sql, tablename, columnname, _owner);
            }

            _DR = ExecuteDataReader(CreateCommand(sql).ExecuteReader);

            while (_DR.Read())
            {
                if (!string.IsNullOrEmpty(_DR["nullable"].ToString()))
                {
                    if (_DR["nullable"].ToString().ToUpper() == "Y")
                    {
                        res.IsNullable = true;
                    }
                    if (_DR["nullable"].ToString().ToUpper() == "N")
                    {
                        res.IsNullable = false;
                    }
                }
                if (_DR["data_length"] != DBNull.Value)
                {
                    res.MaxLength = Convert.ToInt32(_DR["data_length"]);
                }
                if (_DR["data_precision"] != DBNull.Value)
                {
                    res.Precision = Convert.ToInt32(_DR["data_precision"]);
                }
                if (_DR["data_scale"] != DBNull.Value)
                {
                    res.Sacale = Convert.ToInt32(_DR["data_scale"]);
                }

                if (_DR["DATA_DEFAULT"] != DBNull.Value)
                {
                    res.DefaultValue = _DR["DATA_DEFAULT"];
                    //res.DefaultValue = DefValuePostProcessing(res.DefaultValue);
                }
                else
                {
                    res.DefaultValue = null;
                }

                break;
            }

            _DR.Close();

            return(res);
        }
Пример #7
0
        internal virtual DbColumnInformation GetDbColumnInformation(string tablename, string columnname, bool CaseSensivity)
        {
            DbColumnInformation res = new DbColumnInformation();

            res.MaxLength = 50;
            res.IsNullable = true;
            res.AdditionalInfo = "default";

            return res;
        }
Пример #8
0
        internal override DbColumnInformation GetDbColumnInformation(string tablename, string columnname, bool CaseSensivity)
        {
            DbColumnInformation res = new DbColumnInformation();

            string sql = "";
            if (!CaseSensivity)
                sql = string.Format("select max(length({0})) from {1}", columnname, tablename);
            else
                sql = string.Format("select max(length({0}{1}{2})) from {0}{3}{2}", _open_bracket, columnname, _close_bracket, tablename);
            var res2 = ExecuteScalarCommand(CreateCommand(sql).ExecuteScalar);
            if (res2 != null && res2 != DBNull.Value)
            {
                var mlen = Convert.ToInt32(res2);
                res.MaxLength = (mlen > 0 ? mlen : 50);
            }

            _DR = ExecuteDataReader(CreateCommand(string.Format("pragma table_info({0})",tablename)).ExecuteReader);
            while (_DR.Read())
            {
                if (CaseSensivity)
                {
                    if (_DR["name"].ToString() == columnname)
                    {
                        res.IsNullable = !Convert.ToBoolean(_DR["notnull"]);
                        if (_DR["dflt_value"] != DBNull.Value)
                            res.DefaultValue = _DR["dflt_value"];
                    }
                }
                else
                {
                    if (_DR["name"].ToString().ToLower() == columnname.ToLower())
                    {
                        res.IsNullable = !Convert.ToBoolean(_DR["notnull"]);
                        if (_DR["dflt_value"] != DBNull.Value)
                            res.DefaultValue = _DR["dflt_value"];
                    }
                }
            }

            _DR.Close();

            return res;
        }
Пример #9
0
        internal override DbColumnInformation GetDbColumnInformation(string tablename, string columnname, bool CaseSensivity)
        {
            DbColumnInformation res = new DbColumnInformation();

            string sql = "";

            if (CaseSensivity)
            {
                sql = string.Format("select is_nullable,max_length,precision,scale, dc.definition,c.system_type_id "
                                    + "from sys.tables t inner join sys.columns c on c.object_id=t.object_id  "
                                    + "left outer join sys.default_constraints dc on dc.parent_object_id=c.object_id and c.column_id=dc.parent_column_id "
                                    + "where t.name='{0}' and c.name='{1}'"
                                    , tablename, columnname);
            }
            else
            {
                sql = string.Format("select is_nullable,max_length,precision,scale, dc.definition,c.system_type_id "
                                    + "from sys.tables t inner join sys.columns c on c.object_id=t.object_id  "
                                    + "left outer join sys.default_constraints dc on dc.parent_object_id=c.object_id and c.column_id=dc.parent_column_id "
                                    + "where lower(t.name)=lower('{0}') and lower(c.name)=lower('{1}')"
                                    , tablename, columnname);
            }

            _DR = ExecuteDataReader(CreateCommand(sql).ExecuteReader);

            while (_DR.Read())
            {
                res.IsNullable = (bool)_DR["is_nullable"];
                res.MaxLength  = Convert.ToInt32(_DR["max_length"]);
                res.Precision  = Convert.ToInt32(_DR["precision"]);
                res.Sacale     = Convert.ToInt32(_DR["scale"]);
                if (_DR["definition"] != DBNull.Value)
                {
                    res.DefaultValue = _DR["definition"];
                    res.DefaultValue = DefValuePostProcessing(res.DefaultValue);
                }
                else
                {
                    res.DefaultValue = null;
                }

                if (_DR["system_type_id"] != null && _DR["system_type_id"] != DBNull.Value)
                {
                    int coltype = Convert.ToInt32(_DR["system_type_id"]);
                    if (coltype == 35)
                    {
                        res.MaxLength = 0;
                    }
                }

                break;
            }

            _DR.Close();

            /*var result = ExecuteScalarCommand(CreateCommand(sql).ExecuteScalar);
             * if (result != null && result != DBNull.Value)
             *  res.MaxLength = Convert.ToInt32(result);*/

            return(res);
        }