public static ColumnMetaData[] cci_get_result_info(int req_handle)
        {
            int stmt_type = 0;
            int col_num = 0;

            IntPtr pt = cci_get_result_info_internal(req_handle, ref stmt_type, ref col_num);
            ColumnMetaData[] item = new ColumnMetaData[col_num];

            for (int i = 0; i < col_num; i++)
            {
                ColumnMetaData data = new ColumnMetaData();
                try
                {
                    T_CCI_COL_INFO tmp =
                        (T_CCI_COL_INFO)Marshal.PtrToStructure((IntPtr)((UInt32)pt +
                        i * Marshal.SizeOf(typeof(T_CCI_COL_INFO))), typeof(T_CCI_COL_INFO));
                    data.Type = (CUBRIDDataType)tmp.ext_type;

                    data.IsAutoIncrement = int_to_bool(tmp.is_auto_increment - 0);
                    data.IsForeignKey = int_to_bool(tmp.is_foreign_key - 0);
                    data.IsNullable = int_to_bool(tmp.is_non_null - 0) == true ? false : true;
                    data.IsPrimaryKey = int_to_bool(tmp.is_primary_key - 0);
                    data.IsReverseIndex = int_to_bool(tmp.is_reverse_index - 0);
                    data.IsReverseUnique = int_to_bool(tmp.is_reverse_unique - 0);
                    data.IsShared = int_to_bool(tmp.is_shared - 0);
                    data.IsUniqueKey = int_to_bool(tmp.is_unique_key - 0);
                    data.Precision = tmp.precision;
                    data.RealName = tmp.class_name;
                    data.Name = tmp.col_name;
                    data.Scale = tmp.scale;
                    data.Table = tmp.class_name;
                    data.Type = (CUBRIDDataType)tmp.ext_type;
                }
                catch
                {
                    //Not throw exception, just set default value
                }
                finally
                {
                    item[i] = data;
                }          
            }
            return item;
        }
        public static ColumnMetaData[] cci_get_result_info(CUBRIDConnection conn, int req_handle)
        {
            int stmt_type = 0;
            int col_num   = 0;

            byte[] name;

            IntPtr pt = cci_get_result_info_internal(req_handle, ref stmt_type, ref col_num);

            ColumnMetaData[] item = new ColumnMetaData[col_num];

            for (int i = 0; i < col_num; i++)
            {
                ColumnMetaData data = new ColumnMetaData();
                try
                {
                    T_CCI_COL_INFO tmp;
                    IntPtr         data_ptr;
                    data_ptr = Utils.AddIntPtr(pt, i * Marshal.SizeOf(typeof(T_CCI_COL_INFO)));
                    tmp      = (T_CCI_COL_INFO)Marshal.PtrToStructure(data_ptr, typeof(T_CCI_COL_INFO));

                    data.Type            = (CUBRIDDataType)tmp.ext_type;
                    data.IsAutoIncrement = int_to_bool(tmp.is_auto_increment - 0);
                    data.IsForeignKey    = int_to_bool(tmp.is_foreign_key - 0);
                    data.IsNullable      = int_to_bool(tmp.is_non_null - 0) == true ? false : true;
                    data.IsPrimaryKey    = int_to_bool(tmp.is_primary_key - 0);
                    data.IsReverseIndex  = int_to_bool(tmp.is_reverse_index - 0);
                    data.IsReverseUnique = int_to_bool(tmp.is_reverse_unique - 0);
                    data.IsShared        = int_to_bool(tmp.is_shared - 0);
                    data.IsUniqueKey     = int_to_bool(tmp.is_unique_key - 0);
                    data.Precision       = tmp.precision;
                    data.Scale           = tmp.scale;
                    data.Type            = (CUBRIDDataType)tmp.ext_type;

                    if (conn.GetEncoding().Equals(Encoding.UTF8))
                    {
                        name      = Encoding.UTF8.GetBytes(tmp.col_name);
                        data.Name = Encoding.UTF8.GetString(name);

                        name          = Encoding.UTF8.GetBytes(tmp.class_name);
                        data.RealName = Encoding.UTF8.GetString(name);
                        data.Table    = Encoding.UTF8.GetString(name);
                    }
                    else
                    {
                        name      = Encoding.Unicode.GetBytes(tmp.col_name);
                        data.Name = Encoding.Unicode.GetString(name);

                        name          = Encoding.Unicode.GetBytes(tmp.class_name);
                        data.RealName = Encoding.Unicode.GetString(name);
                        data.Table    = Encoding.Unicode.GetString(name);
                    }
                }
                catch
                {
                    //Not throw exception, just set default value
                }
                finally
                {
                    item[i] = data;
                }
            }
            return(item);
        }
 /*
 internal CUBRIDDataReader(CUBRIDCommand stmt, int handle, int count, ColumnMetaData[] columnInfos)
 {
   this.stmt = stmt;
   conn = (CUBRIDConnection)stmt.Connection;
   this.handle = handle;
   resultCount = count;
   columnMetaData = columnInfos;
   currentRow = 0;
   resultTuple = new ResultTuple(columnInfos.Length);
   commandBehavior = CommandBehavior.Default;
   InitColumnTypeName();
 }
 */
 internal CUBRIDDataReader(CUBRIDCommand stmt, int handle, int count, ColumnMetaData[] columnInfos, int tupleCount)
 {
   this.stmt = stmt;
   conn = (CUBRIDConnection)stmt.Connection;
   this.handle = handle;
   resultCount = count;
   columnMetaData = columnInfos;
   currentRow = 0;
   this.tupleCount = tupleCount;
   resultTuple = new ResultTuple(columnInfos.Length);
   commandBehavior = CommandBehavior.Default;
   InitColumnTypeName();
 }
        /// <summary>
        ///   Returns a <see cref="T:System.Data.DataTable" /> that describes the column metadata of the <see
        ///    cref="T:System.Data.Common.DbDataReader" />.
        /// </summary>
        /// <returns> A <see cref="T:System.Data.DataTable" /> that describes the column metadata. </returns>
        public override DataTable GetSchemaTable()
        {
            if (FieldCount == 0)
            {
                return(null);
            }

            DataTable dataTableSchema = new DataTable("SchemaTable");

            //http://msdn.microsoft.com/en-us/library/system.data.datatablereader.getschematable.aspx

            /*
             * ColumnName	The name of the column; this might not be unique. If the column name cannot be determined, a null value is returned. This name always reflects the most recent naming of the column in the current view or command text.
             * ColumnOrdinal	The ordinal of the column. This is zero for the bookmark column of the row, if any. Other columns are numbered starting with 1. This column cannot contain a null value.
             * ColumnSize	The maximum possible length of a value in the column. For columns that use a fixed-length data type, this is the size of the data type.
             * NumericPrecision	If DbType is a numeric data type, this is the maximum precision of the column. The precision depends on the definition of the column. If DbType is not a numeric data type, this is a null value.
             * NumericScale	If DbType is Decimal, the number of digits to the right of the decimal point. Otherwise, this is a null value.
             * DataType	Maps to the .Net Framework type of the column.
             * ProviderType	The indicator of the column's data type.
             * IsLong	true if the column contains a BLOB that contains very long data.
             * AllowDBNull	true if the consumer can set the column to a null value. Otherwise, false. A column may contain null values, even if it cannot be set to a null value.
             * IsReadOnly	true if the column can not be modified; otherwise, false.
             * IsRowVersion	Set if the column contains a persistent row identifier that cannot be written to, and has no meaningful value except to identity the row.
             * IsUnique	true: No two rows in the base table-the table returned in BaseTableName-can have the same value in this column. IsUnique is guaranteed to be true if the column constitutes a key by itself or if there is a constraint of type UNIQUE that applies only to this column. false: The column can contain duplicate values in the base table.The default for this column is false.
             * IsKey	true: The column is one of a set of columns in the rowset that, taken together, uniquely identify the row. The set of columns with IsKey set to true must uniquely identify a row in the rowset. There is no requirement that this set of columns is a minimal set of columns. This set of columns may be generated from a base table primary key, a unique constraint or a unique index. false: The column is not required to uniquely identify the row.
             * IsAutoIncrement	true if the column assigns values to new rows in fixed increments; otherwise, false. The default value for this column is false.
             * BaseSchemaName	The name of the schema in the database that contains the column. NULL if the base catalog name cannot be determined. The default for this column is a null value.
             * BaseCatalogName	The name of the catalog in the data store that contains the column. NULL if the base catalog name cannot be determined. The default value for this column is a null value.
             * BaseTableName	The name of the table or view in the data store that contains the column. A null value if the base table name cannot be determined. The default value of this column is a null value.
             * BaseColumnName	The name of the column in the data store. This might be different than the column name returned in the ColumnName column if an alias was used. A null value if the base column name cannot be determined or if the rowset column is derived, but not identical to, a column in the data store. The default value for this column is a null value.
             * IsAliased	true if the column name is an alias; otherwise, false.
             * IsExpression	true if the column is an expression; otherwise, false.
             */

            dataTableSchema.Columns.Add("ColumnName", typeof(string));
            dataTableSchema.Columns.Add("ColumnOrdinal", typeof(int));
            dataTableSchema.Columns.Add("ColumnSize", typeof(int));
            dataTableSchema.Columns.Add("NumericPrecision", typeof(int));
            dataTableSchema.Columns.Add("NumericScale", typeof(int));
            dataTableSchema.Columns.Add("IsUnique", typeof(bool));
            dataTableSchema.Columns.Add("IsReverseUnique", typeof(bool));
            dataTableSchema.Columns.Add("IsKey", typeof(bool));
            DataColumn dc = dataTableSchema.Columns["IsKey"];

            dc.AllowDBNull = false;
            dataTableSchema.Columns.Add("IsForeignKey", typeof(bool));
            dataTableSchema.Columns.Add("IsPrimaryKey", typeof(bool));
            dataTableSchema.Columns.Add("IsShared", typeof(bool));
            dataTableSchema.Columns.Add("BaseCatalogName", typeof(string));
            dataTableSchema.Columns.Add("BaseColumnName", typeof(string));
            dataTableSchema.Columns.Add("BaseSchemaName", typeof(string));
            dataTableSchema.Columns.Add("BaseTableName", typeof(string));
            dataTableSchema.Columns.Add("DataType", typeof(Type));
            dataTableSchema.Columns.Add("ProviderType", typeof(CUBRIDDataType));
            dataTableSchema.Columns.Add("AllowDBNull", typeof(bool));
            dataTableSchema.Columns.Add("DefaultValue", typeof(string));
            dataTableSchema.Columns.Add("IsAliased", typeof(bool));
            dataTableSchema.Columns.Add("IsExpression", typeof(bool));
            dataTableSchema.Columns.Add("IsIdentity", typeof(bool));
            dataTableSchema.Columns.Add("IsAutoIncrement", typeof(bool));
            dataTableSchema.Columns.Add("IsRowVersion", typeof(bool));
            dataTableSchema.Columns.Add("IsHidden", typeof(bool));
            dataTableSchema.Columns.Add("IsLong", typeof(bool));
            dataTableSchema.Columns.Add("IsReadOnly", typeof(bool));

            for (int i = 0; i < FieldCount; i++)
            {
                ColumnMetaData columnMetadata = columnMetaData[i];

                DataRow row = dataTableSchema.NewRow();

                row["ColumnName"]    = columnMetadata.Name;
                row["ColumnOrdinal"] = i + 1;
                row["ColumnSize"]    = columnMetadata.Precision;
                int precision = columnMetadata.Precision;
                if (precision != -1 && Int16.MaxValue > precision)
                {
                    row["NumericPrecision"] = Convert.ToInt16(precision);
                }
                int scale = columnMetadata.Scale;
                if (scale != -1 && Int16.MaxValue > scale)
                {
                    row["NumericScale"] = Convert.ToInt16(scale);
                }

                row["DataType"]     = GetFieldType(i);
                row["ProviderType"] = columnMetadata.Type;

                row["AllowDBNull"] = columnMetadata.IsNullable;

                row["DefaultValue"] = columnMetadata.DefaultValue;

                row["IsUnique"]        = columnMetadata.IsUniqueKey;
                row["IsReverseUnique"] = columnMetadata.IsReverseUnique;
                row["IsKey"]           = columnMetadata.IsPrimaryKey;
                row["IsAutoIncrement"] = columnMetadata.IsAutoIncrement;
                row["IsForeignKey"]    = columnMetadata.IsForeignKey;
                row["IsPrimaryKey"]    = columnMetadata.IsPrimaryKey;
                row["IsShared"]        = columnMetadata.IsShared;

                row["BaseCatalogName"] = null;
                row["BaseSchemaName"]  = null;

                row["BaseColumnName"] = columnMetadata.Name;
                row["BaseTableName"]  = columnMetadata.Table;

                row["IsAliased"]    = false;
                row["IsExpression"] = false;
                row["IsIdentity"]   = false;
                row["IsRowVersion"] = false;
                row["IsHidden"]     = false;
                row["IsLong"]       = false;
                //TODO True if the data type of the column is String and its MaxLength property is -1. Otherwise, false.
                row["IsReadOnly"] = false;

                dataTableSchema.Rows.Add(row);
            }

            return(dataTableSchema);
        }
Beispiel #5
0
        public static ColumnMetaData[] cci_get_result_info(CUBRIDConnection conn, int req_handle)
        {
            int stmt_type = 0;
            int col_num   = 0;
            int n;

            byte[] name = new byte[MAX_TBALE_COLUMN_NAME_LENGTH];

            IntPtr pt = cci_get_result_info_internal(req_handle, ref stmt_type, ref col_num);

            ColumnMetaData[] item = new ColumnMetaData[col_num];

            for (int i = 0; i < col_num; i++)
            {
                ColumnMetaData data = new ColumnMetaData();
                try
                {
                    T_CCI_COL_INFO tmp =
                        (T_CCI_COL_INFO)Marshal.PtrToStructure((IntPtr)((UInt32)pt +
                                                                        i * Marshal.SizeOf(typeof(T_CCI_COL_INFO))), typeof(T_CCI_COL_INFO));
                    data.Type = (CUBRIDDataType)tmp.ext_type;

                    data.IsAutoIncrement = int_to_bool(tmp.is_auto_increment - 0);
                    data.IsForeignKey    = int_to_bool(tmp.is_foreign_key - 0);
                    data.IsNullable      = int_to_bool(tmp.is_non_null - 0) == true ? false : true;
                    data.IsPrimaryKey    = int_to_bool(tmp.is_primary_key - 0);
                    data.IsReverseIndex  = int_to_bool(tmp.is_reverse_index - 0);
                    data.IsReverseUnique = int_to_bool(tmp.is_reverse_unique - 0);
                    data.IsShared        = int_to_bool(tmp.is_shared - 0);
                    data.IsUniqueKey     = int_to_bool(tmp.is_unique_key - 0);
                    data.Precision       = tmp.precision;
                    data.Scale           = tmp.scale;
                    data.Type            = (CUBRIDDataType)tmp.ext_type;

                    Marshal.Copy(tmp.col_name, name, 0, MAX_TBALE_COLUMN_NAME_LENGTH);
                    for (n = 0; n < MAX_TBALE_COLUMN_NAME_LENGTH; n++)
                    {
                        if (name[n] == 0)
                        {
                            break;
                        }
                    }
                    if (conn.GetEncoding().Equals(Encoding.UTF8))
                    {
                        data.Name = Encoding.UTF8.GetString(name, 0, n);
                    }
                    else
                    {
                        data.Name = Encoding.Unicode.GetString(name, 0, n);
                    }

                    Marshal.Copy(tmp.class_name, name, 0, MAX_TBALE_COLUMN_NAME_LENGTH);
                    for (n = 0; n < MAX_TBALE_COLUMN_NAME_LENGTH; n++)
                    {
                        if (name[n] == 0)
                        {
                            break;
                        }
                    }
                    if (conn.GetEncoding().Equals(Encoding.UTF8))
                    {
                        data.RealName = Encoding.UTF8.GetString(name, 0, n);
                        data.Table    = Encoding.UTF8.GetString(name, 0, n);
                    }
                    else
                    {
                        data.RealName = Encoding.Unicode.GetString(name, 0, n);
                        data.Table    = Encoding.Unicode.GetString(name, 0, n);
                    }
                }
                catch
                {
                    //Not throw exception, just set default value
                }
                finally
                {
                    item[i] = data;
                }
            }
            return(item);
        }