interval.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*!
  2. \file lib/db/dbmi_base/interval.c
  3. \brief DBMI Library (base) - range, interval procedures
  4. (C) 1999-2009, 2011 by the GRASS Development Team
  5. This program is free software under the GNU General Public License
  6. (>=v2). Read the file COPYING that comes with GRASS for details.
  7. \author Joel Jones (CERL/UIUC), Radim Blazek
  8. \author Doxygenized by Martin Landa <landa.martin gmail.com> (2011)
  9. */
  10. #include <grass/dbmi.h>
  11. /*!
  12. \brief Define range based on SQL data type
  13. \param sqltype SQL data type
  14. \param[out] from
  15. \param[out] to
  16. */
  17. void db_interval_range(int sqltype, int *from, int *to)
  18. {
  19. switch (sqltype) {
  20. case DB_SQL_TYPE_DATE:
  21. *from = DB_YEAR;
  22. *to = DB_DAY;
  23. return;
  24. case DB_SQL_TYPE_TIME:
  25. *from = DB_HOUR;
  26. *to = DB_FRACTION;
  27. return;
  28. }
  29. if (sqltype & DB_YEAR)
  30. *from = DB_YEAR;
  31. else if (sqltype & DB_MONTH)
  32. *from = DB_MONTH;
  33. else if (sqltype & DB_DAY)
  34. *from = DB_DAY;
  35. else if (sqltype & DB_HOUR)
  36. *from = DB_HOUR;
  37. else if (sqltype & DB_MINUTE)
  38. *from = DB_MINUTE;
  39. else if (sqltype & DB_SECOND)
  40. *from = DB_SECOND;
  41. else if (sqltype & DB_FRACTION)
  42. *from = DB_FRACTION;
  43. else
  44. *from = 0;
  45. if (sqltype & DB_FRACTION)
  46. *to = DB_FRACTION;
  47. else if (sqltype & DB_SECOND)
  48. *to = DB_SECOND;
  49. else if (sqltype & DB_MINUTE)
  50. *to = DB_MINUTE;
  51. else if (sqltype & DB_HOUR)
  52. *to = DB_HOUR;
  53. else if (sqltype & DB_DAY)
  54. *to = DB_DAY;
  55. else if (sqltype & DB_MONTH)
  56. *to = DB_MONTH;
  57. else if (sqltype & DB_YEAR)
  58. *to = DB_YEAR;
  59. else
  60. *to = 0;
  61. }