Zones.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*
  2. * The contents of this file are subject to the Initial
  3. * Developer's Public License Version 1.0 (the "License");
  4. * you may not use this file except in compliance with the
  5. * License. You may obtain a copy of the License at
  6. * http://www.ibphoenix.com/main.nfs?a=ibphoenix&page=ibp_idpl.
  7. *
  8. * Software distributed under the License is distributed AS IS,
  9. * WITHOUT WARRANTY OF ANY KIND, either express or implied.
  10. * See the License for the specific language governing rights
  11. * and limitations under the License.
  12. *
  13. * The Original Code was created by Adriano dos Santos Fernandes
  14. * for the Firebird Open Source RDBMS project.
  15. *
  16. * Copyright (c) 2008 Adriano dos Santos Fernandes <[email protected]>
  17. * and all contributors signed below.
  18. *
  19. * All Rights Reserved.
  20. * Contributor(s): ______________________________________.
  21. * Alex Peshkoff
  22. */
  23. #include "UdrCppExample.h"
  24. using namespace Firebird;
  25. //------------------------------------------------------------------------------
  26. /***
  27. create procedure gen_dates (
  28. start_date timestamp with time zone not null,
  29. n_days integer not null
  30. ) returns (
  31. out_date timestamp with time zone not null
  32. )
  33. external name 'udrcpp_example!gen_dates'
  34. engine udr;
  35. ***/
  36. FB_UDR_BEGIN_PROCEDURE(gen_dates)
  37. // Without InMessage/OutMessage definitions, messages will be byte-based.
  38. // Procedure variables.
  39. unsigned inOffsetStartDate, inOffsetNDays, outNullOffset, outOffset;
  40. // Get offsets once per procedure.
  41. FB_UDR_CONSTRUCTOR
  42. {
  43. AutoRelease<IMessageMetadata> inMetadata(metadata->getInputMetadata(status));
  44. inOffsetStartDate = inMetadata->getOffset(status, 0);
  45. inOffsetNDays = inMetadata->getOffset(status, 1);
  46. // printf("SQLtype in = %d\n", inMetadata->getType(status, 0));
  47. AutoRelease<IMessageMetadata> outMetadata(metadata->getOutputMetadata(status));
  48. outNullOffset = outMetadata->getNullOffset(status, 0);
  49. outOffset = outMetadata->getOffset(status, 0);
  50. // printf("SQLtype out = %d\n", outMetadata->getType(status, 0));
  51. }
  52. /*** Procedure destructor.
  53. FB_UDR_DESTRUCTOR
  54. {
  55. }
  56. ***/
  57. FB_UDR_EXECUTE_PROCEDURE
  58. {
  59. counter = *(ISC_LONG*) (in + procedure->inOffsetNDays);
  60. run = *(ISC_TIMESTAMP_TZ*) (in + procedure->inOffsetStartDate);
  61. *(ISC_SHORT*) (out + procedure->outNullOffset) = FB_FALSE;
  62. }
  63. // After procedure's execute definition, starts the result set definition.
  64. FB_UDR_FETCH_PROCEDURE
  65. {
  66. if (--counter < 0)
  67. return false;
  68. *(ISC_TIMESTAMP_TZ*) (out + procedure->outOffset) = run;
  69. run.utc_timestamp.timestamp_date++;
  70. return true;
  71. }
  72. /*** ResultSet destructor.
  73. ~ResultSet()
  74. {
  75. }
  76. ***/
  77. // ResultSet variables.
  78. ISC_LONG counter;
  79. ISC_TIMESTAMP_TZ run;
  80. FB_UDR_END_PROCEDURE
  81. /***
  82. create procedure gen_dates2 (
  83. start_date timestamp with time zone not null,
  84. n_days integer not null
  85. ) returns (
  86. out_date timestamp with time zone not null
  87. )
  88. external name 'udrcpp_example!gen_dates2'
  89. engine udr;
  90. ***/
  91. FB_UDR_BEGIN_PROCEDURE(gen_dates2)
  92. FB_UDR_MESSAGE(InMessage,
  93. (FB_TIMESTAMP_TZ, start_date)
  94. (FB_INTEGER, n_days)
  95. );
  96. FB_UDR_MESSAGE(OutMessage,
  97. (FB_TIMESTAMP_TZ, o_date)
  98. );
  99. FB_UDR_EXECUTE_PROCEDURE
  100. {
  101. out->o_dateNull = FB_FALSE;
  102. out->o_date = in->start_date;
  103. out->o_date.utcTimestamp.date--;
  104. counter = in->n_days;
  105. }
  106. FB_UDR_FETCH_PROCEDURE
  107. {
  108. out->o_date.utcTimestamp.date++;
  109. return counter-- > 0;
  110. }
  111. ISC_LONG counter;
  112. FB_UDR_END_PROCEDURE