Exemplo n.º 1
0
        public void GetBoolean()
        {
            HsqlDataReader testSubject = NewTestSubject();

            testSubject.GetBoolean(ColumnOrdinalFor.Boolean);

            Assert.Fail("TODO");
        }
Exemplo n.º 2
0
        /// <summary>
        /// Computes the key info dictionary for the column metadata of the
        /// given data reader.
        /// </summary>
        /// <remarks>
        /// Depending upon the column metadata already present in the data
        /// reader, it may be required to perform further access to the
        /// originating data source using the reader's
        /// <c>OriginatingConnection</c>.  This in turn implies that the
        /// <c>OriginatingConnection</c> must be open and must still
        /// represent the originating session on the originating data source;
        /// otherwise, the reported key info may be incorrect or the attempt
        /// access the data source may simply fail.
        /// </remarks>
        /// <param name="reader">
        /// The reader for which to compute the column metadata key info map.
        /// </param>
        /// <returns>
        /// Map {ColumnIdentifier=&gt;KeyInfo}
        /// </returns>
        /// <exception cref="HsqlDataSourceException">
        /// If a data access error occurs.
        /// </exception>
        internal static Dictionary <ColumnIdentifier, KeyInfo> GetKeyInfo(
            HsqlDataReader reader)
        {
            ResultMetaData metaData = reader.m_result.metaData;
            Dictionary <TableIdentifier, object> tableSet
                = new Dictionary <TableIdentifier, object>();
            object placeholder = new object();

            string[] schemaNames = metaData.schemaNames;
            string[] tableNames  = metaData.tableNames;
            string[] columnNames = metaData.colNames;
            int      count       = columnNames.Length;

            for (int i = 0; i < count; i++)
            {
                string tableName  = tableNames[i];
                string columnName = columnNames[i];

                if (string.IsNullOrEmpty(tableName) ||
                    string.IsNullOrEmpty(columnName))
                {   // not a table column
                    continue;
                }

                string          schemaName      = schemaNames[i];
                TableIdentifier tableIdentifier = new TableIdentifier(
                    schemaName, tableName);

                tableSet[tableIdentifier] = placeholder;
            }

            Dictionary <ColumnIdentifier, KeyInfo> columnMap
                = new Dictionary <ColumnIdentifier, KeyInfo>();

            if (tableSet.Count == 0)
            {
                return(columnMap);
            }

            StringBuilder sb = new StringBuilder('(');

            count = 0;

            foreach (TableIdentifier tableIdentifier in tableSet.Keys)
            {
                if (count > 0)
                {
                    sb.Append(" OR ");
                }

                count++;

                sb.Append("(bri.table_schem");

                string schemaName = tableIdentifier.m_schema;

                if (string.IsNullOrEmpty(schemaName))
                {
                    sb.Append(" IS NULL ");
                }
                else
                {
                    sb.Append(" = ").Append(StringConverter.toQuotedString(
                                                schemaName, '\'', /*escape inner quotes*/ true));
                }

                string tableName = tableIdentifier.m_table;

                sb.Append(" AND bri.table_name = ").Append(
                    StringConverter.toQuotedString(tableName, '\'',
                                                   /*escape inner quotes*/ true));

                sb.Append(')');
            }

            sb.Append(')');

            string predicate = sb.ToString();

            using (HsqlCommand command =
                       reader.OriginatingConnection.CreateCommand())
            {
                command.CommandText = string.Format(KeyInfoQuery, predicate);
                command.CommandType = CommandType.Text;

                using (HsqlDataReader keyInfoReader = command.ExecuteReader())
                {
                    while (keyInfoReader.Read())
                    {
                        bool isKey = keyInfoReader.GetBoolean(3);

                        if (!isKey)
                        {
                            continue;
                        }

                        string schema = keyInfoReader.GetString(0);
                        string table  = keyInfoReader.GetString(1);
                        string column = keyInfoReader.GetString(2);

                        ColumnIdentifier key = new ColumnIdentifier(schema,
                                                                    table, column);

                        if (!columnMap.ContainsKey(key))
                        {
                            KeyInfo keyInfo = new KeyInfo();

                            keyInfo.m_isKey    = true;
                            keyInfo.m_isUnique = false;

                            columnMap.Add(key, keyInfo);
                        }
                    }
                }
            }

            return(columnMap);
        }