示例#1
0
        private int InternalInitFieldDefs()
        {
            if (queryID <= 0)
            {
                return(0);
            }

            lock (syncRoot)
            {
                recordCount = VistaDBAPI.ivsql_RecCount(queryID);
                columnCount = VistaDBAPI.ivsql_ColumnCount(queryID);
                columns     = new VistaDBColumn[columnCount];
                char colType;
                int  len;

                int           columnCaptionWidth = 128;
                StringBuilder columnCaption      = new StringBuilder(columnCaptionWidth);

                int           columnNameWidth = 128;
                StringBuilder columnName      = new StringBuilder(columnNameWidth);

                VistaDBType columntype;
                bool        allowNull, readOnly, autoIncrement, primaryKey, unique, reservedWord;
                int         dataSize, columnWidth;

                string tempS;
                for (int i = 0; i < columnCount; i++)
                {
                    len = VistaDBAPI.ivsql_ColumnName(queryID, i + 1, columnName, columnNameWidth);
                    columnName.Length = len;

                    len = VistaDBAPI.ivsql_ColumnCaption(queryID, i + 1, columnCaption, columnCaptionWidth);
                    columnCaption.Length = len;

                    colType = VistaDBAPI.ivsql_ColumnType(queryID, i + 1);
                    tempS   = colType.ToString();

                    columntype = VistaDBAPI.NetDataType(tempS);

                    dataSize      = 0;                     // default
                    columnWidth   = 0;                     // default
                    allowNull     = !VistaDBAPI.ivsql_ColumnRequired(queryID, i + 1);
                    readOnly      = VistaDBAPI.ivsql_ColumnReadOnly(queryID, i + 1);
                    autoIncrement = VistaDBAPI.ivsql_ColumnIsIdentity(queryID, i + 1);
                    primaryKey    = VistaDBAPI.ivsql_ColumnIsPrimaryKey(queryID, i + 1);
                    unique        = VistaDBAPI.ivsql_ColumnIsUnique(queryID, i + 1);
                    reservedWord  = VistaDBAPI.ivsql_IsReservedWord(columnName.ToString());

                    switch (columntype)
                    {
                    case VistaDBType.Character:
                        columnWidth = VistaDBAPI.ivsql_ColumnWidth(queryID, i + 1);
                        dataSize    = columnWidth;
                        break;

                    case VistaDBType.Varchar:
                        columnWidth = VistaDBAPI.ivsql_ColumnWidth(queryID, i + 1);
                        dataSize    = columnWidth;
                        break;

                    case VistaDBType.Date:
                        dataSize = 8;
                        break;

                    case VistaDBType.DateTime:
                        dataSize = 8;
                        break;

                    case VistaDBType.Boolean:
                        dataSize = 2;
                        break;

                    case VistaDBType.Int32:
                        dataSize = 4;
                        break;

                    case VistaDBType.Int64:
                        dataSize = 8;
                        break;

                    case VistaDBType.Currency:
                        dataSize = 8;
                        break;

                    case VistaDBType.Double:
                        dataSize = 8;
                        break;

                    case VistaDBType.Memo:
                    case VistaDBType.Blob:
                    case VistaDBType.Picture:
                        dataSize = 2147483647;
                        break;

                    case VistaDBType.Guid:
                        dataSize = 16;
                        break;
                    }

                    columns[i] = new VistaDBColumn(columnName.ToString(), columntype, dataSize, (short)columnWidth, 0, allowNull, readOnly, primaryKey, unique, autoIncrement, 0, "", columnCaption.ToString(), "", reservedWord, false, false, false, false);
                }
            }

            return(errorNumber);
        }