Esempio n. 1
0
        // Retrieve the column value from the ESE.
        // Returns the properly-escaped string suitable for TSV file.
        string getStringValue(TextWriter bw, JET_COLUMNID idColumn, int itagSequence, JET_coltyp ct, JET_CP cp)
        {
            JET_RETINFO ri = new JET_RETINFO();

            ri.itagSequence = itagSequence;

            int cbSize;

            Api.JetRetrieveColumn(sess.idSession, idTable, idColumn,
                                  buff, buff.Length, out cbSize, RetrieveColumnGrbit.None, ri);
            if (cbSize <= 0)
            {
                return("");
            }

            if (ct == JET_coltyp.Currency)                       // int64
            {
                Debug.Assert(8 == cbSize);
                return(BitConverter.ToUInt64(buff, 0).ToString("X16"));
            }

            if (ct == JET_coltyp.Long)                       // int32
            {
                Debug.Assert(4 == cbSize);
                return(BitConverter.ToUInt32(buff, 0).ToString("X8"));
            }

            if (ct == JET_coltyp.Short)                      // int16
            {
                Debug.Assert(2 == cbSize);
                return(BitConverter.ToUInt16(buff, 0).ToString("X4"));
            }

            if (ct == JET_coltyp.UnsignedByte)               // uint8
            {
                Debug.Assert(1 == cbSize);
                return(buff[0].ToString("X2"));
            }

            if (ct == JET_coltyp.DateTime)                   // DateTime
            {
                Debug.Assert(8 == cbSize);
                double   dbl = BitConverter.ToDouble(buff, 0);
                DateTime dt  = Conversions.ConvertDoubleToDateTime(dbl);
                return(dt.ToString("o"));
            }

            if (ct == JET_coltyp.Text || ct == JET_coltyp.LongText)              // Text
            {
                if (cp == JET_CP.Unicode)
                {
                    return(TSV.EscapeUnicode(buff, cbSize));
                }
                else
                {
                    return(TSV.EscapeASCII(buff, cbSize));
                }
            }
            return(Convert.ToBase64String(buff, 0, cbSize));                     // Anything else
        }
Esempio n. 2
0
        // Put the column value to the ESE.
        void LoadVal(string strVal, JET_COLUMNID idColumn, JET_coltyp ct, JET_CP cp)
        {
            if (String.IsNullOrEmpty(strVal))
            {
                return;
            }

            byte[] val = null;
            if (ct == JET_coltyp.Currency)                                               // int64
            {
                val = BitConverter.GetBytes(Convert.ToUInt64(strVal, 16));
            }
            else if (ct == JET_coltyp.Long)                                              // int32
            {
                val = BitConverter.GetBytes(Convert.ToUInt32(strVal, 16));
            }
            else if (ct == JET_coltyp.Short)                                             // int16
            {
                val = BitConverter.GetBytes(Convert.ToUInt16(strVal, 16));
            }
            else if (ct == JET_coltyp.UnsignedByte)                                      // uint8
            {
                val = new byte[1] {
                    Convert.ToByte(strVal, 16)
                }
            }
            ;
            else if (ct == JET_coltyp.DateTime)                                          // DateTime
            {
                DateTime dt  = DateTime.Parse(strVal, null, System.Globalization.DateTimeStyles.RoundtripKind);
                double   dbl = dt.ToOADate();
                val = BitConverter.GetBytes(dbl);
            }
            else if (ct == JET_coltyp.Text || ct == JET_coltyp.LongText)                 // Text
            {
                if (cp == JET_CP.Unicode)
                {
                    val = TSV.UnescapeUnicode(strVal).ToArray();
                }
                else
                {
                    val = TSV.UnescapeASCII(strVal).ToArray();
                }
            }
            else
            {
                val = Convert.FromBase64String(strVal);                                  // Anything else
            }
            JET_SETINFO si = new JET_SETINFO();

            si.itagSequence = 0;
            Api.JetSetColumn(sess.idSession, idTable, idColumn, val, val.Length, SetColumnGrbit.None, si);
        }