CSQLiteQuery.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace OTSModelSharp.DTLBase
  7. {
  8. public class CSQLiteQuery : IDBQueryBase
  9. {
  10. private System.Data.SQLite.SQLiteDataReader reader;
  11. public CSQLiteQuery(System.Data.SQLite.SQLiteDataReader a_reader)
  12. {
  13. reader = a_reader;
  14. }
  15. public void Close()
  16. {
  17. reader.Close();
  18. }
  19. public byte[] GetColBlobValue(int a_nColIndex, int a_nLen)
  20. {
  21. byte[] val = new byte[a_nLen];
  22. reader.GetBytes(a_nColIndex, 0, val, 0, a_nLen);
  23. return val;
  24. }
  25. public int GetColCount()
  26. {
  27. return reader.FieldCount;
  28. }
  29. public double GetColFloatValue(int a_nColIndex, double a_dNullValue = 0)
  30. {
  31. return reader.GetDouble(a_nColIndex);
  32. }
  33. public int GetColIntValue(int a_nColIndex, int a_nNullValue)
  34. {
  35. return reader.GetInt32(a_nColIndex);
  36. }
  37. public string GetColName(int a_nColIndex)
  38. {
  39. return reader.GetName(a_nColIndex);
  40. }
  41. public string GetColStringValue(int a_nColIndex, string a_sNullValue = "")
  42. {
  43. return reader.GetString(a_nColIndex);
  44. }
  45. public Type GetColType(int a_nColIndex)
  46. {
  47. return reader.GetFieldType(a_nColIndex);
  48. }
  49. public string GetColValue(int a_nColIndex)
  50. {
  51. string readerValue = "";
  52. while (reader.Read())
  53. {
  54. readerValue = (string)reader.GetValue(a_nColIndex);
  55. }
  56. return readerValue;
  57. }
  58. public bool IsColNull(int a_nColIndex)
  59. {
  60. return reader.IsDBNull(a_nColIndex);
  61. }
  62. public bool IsEOF()
  63. {
  64. return !reader.HasRows;
  65. }
  66. public bool IsValid()
  67. {
  68. return !reader.IsClosed;
  69. }
  70. public bool NextRow()
  71. {
  72. reader.Read();
  73. return true;
  74. }
  75. }
  76. }