Exemplo n.º 1
0
        /// <summary>
        /// Returns the value of the column at the given position in the table schema. The first column is 1.
        /// </summary>
        public object GetValue(int fieldNo)
        {
            DateTime      dt;
            int           dataLen;
            StringBuilder tmpstr;

            object res;

            res = null;

            if (queryID <= 0)
            {
                return(null);
            }

            if (IsNull(fieldNo))
            {
                res = null;
            }
            else
            {
                switch (columns[fieldNo].VistaDBType)
                {
                case VistaDBType.Character:
                    dataLen       = columns[fieldNo].DataSize;
                    tmpstr        = new StringBuilder(dataLen);
                    dataLen       = VistaDBAPI.ivsql_GetString(queryID, fieldNo + 1, tmpstr, dataLen);
                    tmpstr.Length = dataLen;
                    res           = tmpstr.ToString();
                    break;

                case VistaDBType.Date:
                    long longdate = VistaDBAPI.ivsql_GetDate(queryID, fieldNo + 1);
                    dt  = new DateTime(longdate);
                    res = dt;
                    break;

                case VistaDBType.DateTime:
                    long longdatetime = VistaDBAPI.ivsql_GetDateTime(queryID, fieldNo + 1);

                    if (longdatetime == 0)
                    {
                        res = null;
                    }
                    else
                    {
                        if ((longdatetime >= DateTime.MinValue.Ticks) && (longdatetime <= DateTime.MaxValue.Ticks))
                        {
                            dt  = new DateTime(longdatetime);
                            res = dt;
                        }
                        else
                        {
                            res = null;
                        }
                    }
                    break;

                case VistaDBType.Boolean:
                    res = VistaDBAPI.ivsql_GetBoolean(queryID, fieldNo + 1);
                    break;

                case VistaDBType.Int32:
                    res = VistaDBAPI.ivsql_GetInt32(queryID, fieldNo + 1);
                    break;

                case VistaDBType.Int64:
                    res = VistaDBAPI.ivsql_GetInt64(queryID, fieldNo + 1);
                    break;

                case VistaDBType.Currency:
                    long longValue;
                    longValue = VistaDBAPI.ivsql_GetCurrency(queryID, fieldNo + 1);
                    res       = (decimal)((double)(longValue / 10000d));
                    break;

                case VistaDBType.Double:
                    res = VistaDBAPI.ivsql_GetDouble(queryID, fieldNo + 1);
                    break;

                case VistaDBType.Memo:
                    dataLen = VistaDBAPI.ivsql_GetBlobLength(queryID, fieldNo + 1);
                    tmpstr  = new StringBuilder(dataLen);
                    dataLen = VistaDBAPI.ivsql_GetMemo(queryID, fieldNo + 1, tmpstr, dataLen);

                    tmpstr.Length = dataLen;
                    res           = tmpstr.ToString();
                    break;

                case VistaDBType.Picture:
                case VistaDBType.Blob:
                    int    blobLen = 0;
                    byte[] blobContent;
                    blobContent = null;
                    blobLen     = VistaDBAPI.ivsql_GetBlobLength(queryID, fieldNo + 1);
                    blobContent = new byte[blobLen];
                    VistaDBAPI.ivsql_GetBlob(queryID, fieldNo + 1, blobContent, blobLen);
                    res = blobContent;
                    break;

                case VistaDBType.Varchar:
                    dataLen = columns[fieldNo].DataSize;
                    tmpstr  = new StringBuilder(dataLen);
                    dataLen = VistaDBAPI.ivsql_GetVarchar(queryID, fieldNo + 1, tmpstr, dataLen);

                    tmpstr.Length = dataLen;
                    res           = tmpstr.ToString();
                    break;

                case VistaDBType.Guid:
                    res = VistaDBAPI.ivsql_GetGuid(queryID, fieldNo + 1);
                    break;
                }
            }

            return(res);
        }