locator.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. /*
  2. * Licensed Materials - Property of IBM and/or HCL
  3. *
  4. * IBM Informix Dynamic Server
  5. * (c) Copyright IBM Corporation 1996, 2014 All rights reserved.
  6. * (c) Copyright HCL Technologies Ltd. 2017. All Rights Reserved.
  7. *
  8. ***************************************************************************
  9. *
  10. * Title: locator.h
  11. *
  12. * Description:
  13. * 'locator.h' defines 'loc_t' the locator struct.
  14. *
  15. * Note: This file goes to customers.
  16. ***************************************************************************
  17. */
  18. #ifndef LOCATOR_INCL /* avoid multiple includes */
  19. #define LOCATOR_INCL
  20. #include "ifxtypes.h"
  21. #include "int8.h"
  22. /*
  23. Locators are used to store TEXT or BYTE fields (blobs) in ESQL
  24. programs. The "loc_t" structure is described below. Fields denoted
  25. USER should be set by the user program and will be examined by the DBMS
  26. system. Those denoted SYSTEM are set by the system and may be examined
  27. by the user program. Those denoted INTERNAL contain data only the
  28. system manupilates and examines.
  29. If "loc_loctype" is set to LOCMEMORY, then the blob is stored in
  30. primary memory. The memory buffer is pointed to by the variant
  31. "loc_buffer". The field "loc_bufsize" gives the size of "loc_buffer".
  32. If the "loc_bufsize" is set to "-1" and "loc_mflags" is set to "0"
  33. and the locator is used for a fetch, memory is obtained using "malloc"
  34. and "loc_buffer" and "loc_bufsize" are set.
  35. If "loc_loctype" is set to LOCFILE, then the blob is stored in a file.
  36. The file descriptor of an open operating system file is specified in
  37. "loc_fd".
  38. If "loc_loctype" is set to LOCFNAME, the the blob is stored in a file
  39. and the name of the file is given. The DBMS will open or created the
  40. file at the correct time and in the correct mode.
  41. If the "loc_loctype" is set to LOCUSER, "loc_(open/close/read/write)"
  42. are called. If the blob is an input to a SQL statement, "loc_open" is
  43. called with the parameter "LOC_RONLY". If the blob is an output target
  44. for an SQL statement, "loc_open" is called with the parameter
  45. "LOC_WONLY".
  46. "loc_size" specifies the maximum number of bytes to use when the
  47. locator is an input target to an SQL statement. It specifies the number
  48. of bytes returned if the locator is an output target. If "loc_loctype"
  49. is LOCFILE or LOCUSER, it can be set to -1 to indicate transfer until
  50. end-of-file.
  51. "loc_indicator" is set by the user to -1 to indicate a NULL blob. It
  52. will be set to -1 if a NULL blob is retrieved. If the blob to be
  53. retrieved will not fit in the space provided, the indicator contains
  54. the size of the blob.
  55. "loc_status" is the status return of locator operations.
  56. "loc_type" is the "blob" type (SQLTEXT, SQLBYTES, ...).
  57. "loc_user_env" is a pointer for the user's private use. It is neither
  58. set nor examined by the system. "loc_user_env" as well as the
  59. "loc_union" fieds may be used by user supplied routines to store and
  60. communicate information.
  61. */
  62. typedef struct tag_loc_t
  63. {
  64. int2 loc_loctype; /* USER: type of locator - see below */
  65. union /* variant on 'loc' */
  66. {
  67. struct /* case LOCMEMORY */
  68. {
  69. int4 lc_bufsize; /* USER: buffer size */
  70. char *lc_buffer; /* USER: memory buffer to use */
  71. char *lc_currdata_p;/* INTERNAL: current memory buffer */
  72. mint lc_mflags; /* USER/INTERNAL: memory flags */
  73. /* (see below) */
  74. } lc_mem;
  75. struct /* cases L0CFNAME & LOCFILE */
  76. {
  77. char *lc_fname; /* USER: file name */
  78. mint lc_mode; /* USER: perm. bits used if creating */
  79. mint lc_fd; /* USER: os file descriptior */
  80. int4 lc_position; /* INTERNAL: seek position */
  81. } lc_file;
  82. } lc_union;
  83. int4 loc_indicator; /* USER SYSTEM: indicator */
  84. int4 loc_type; /* USER SYSTEM: type of blob */
  85. int4 loc_size; /* USER SYSTEM: num bytes in blob or -1 */
  86. mint loc_status; /* SYSTEM: status return of locator ops */
  87. char *loc_user_env; /* USER: for the user's PRIVATE use */
  88. int4 loc_xfercount; /* INTERNAL/SYSTEM: Transfer count */
  89. #if defined(__STDC__) || defined(__cplusplus)
  90. mint (*loc_open)(struct tag_loc_t *loc, mint flag, mint bsize);
  91. mint (*loc_close)(struct tag_loc_t *loc);
  92. mint (*loc_read)(struct tag_loc_t *loc, char *buffer, mint buflen);
  93. mint (*loc_write)(struct tag_loc_t *loc, char *buffer, mint buflen);
  94. #else
  95. mint (*loc_open)();
  96. mint (*loc_close)();
  97. mint (*loc_read)();
  98. mint (*loc_write)();
  99. #endif /* defined(__STDC__) || defined(__cplusplus) */
  100. mint loc_oflags; /* USER/INTERNAL: see flag definitions below */
  101. } loc_t;
  102. #define loc_fname lc_union.lc_file.lc_fname
  103. #define loc_fd lc_union.lc_file.lc_fd
  104. #define loc_position lc_union.lc_file.lc_position
  105. #define loc_bufsize lc_union.lc_mem.lc_bufsize
  106. #define loc_buffer lc_union.lc_mem.lc_buffer
  107. #define loc_currdata_p lc_union.lc_mem.lc_currdata_p
  108. #define loc_mflags lc_union.lc_mem.lc_mflags
  109. /* Enumeration literals for loc_loctype */
  110. #define LOCMEMORY 1 /* memory storage */
  111. #define LOCFNAME 2 /* File storage with file name */
  112. #define LOCFILE 3 /* File storage with fd */
  113. #define LOCUSER 4 /* User define functions */
  114. /* passed to loc_open and stored in loc_oflags */
  115. #define LOC_RONLY 0x1 /* read only */
  116. #define LOC_WONLY 0x2 /* write only */
  117. /* LOC_APPEND can be set when the locator is created
  118. * if the file is to be appended to instead of created
  119. */
  120. #define LOC_APPEND 0x4 /* write with append */
  121. #define LOC_TEMPFILE 0x8 /* 4GL tempfile blob */
  122. /* LOC_USEALL can be set to force the maximum size of the blob to always be
  123. * used when the blob is an input source. This is the same as setting the
  124. * loc_size field to -1. Good for LOCFILE or LOCFNAME blobs only.
  125. */
  126. #define LOC_USEALL 0x10 /* ignore loc_size field */
  127. #define LOC_DESCRIPTOR 0x20 /* BLOB is optical descriptor */
  128. /* passed to loc_open and stored in loc_mflags */
  129. #define LOC_ALLOC 0x1 /* free and alloc memory */
  130. /* Flags to indicate if file is on the server or client */
  131. #define LO_CLIENT_FILE 0x20000000
  132. #define LO_SERVER_FILE 0x10000000
  133. #define LO_ALT_NOBUFFER_CUROPEN 0x80000000
  134. /*******************************************************************************
  135. * File open flags used for operating system file open via
  136. * - ifx_lo_copy_to_lo
  137. * - ifx_lo_copy_to_file
  138. * - ifx_file_to_file
  139. *
  140. ******************************************************************************/
  141. #define LO_O_EXCL 0x00000001 /* fail if file exists */
  142. #define LO_O_APPEND 0x00000002 /* append to end of file */
  143. #define LO_O_TRUNC 0x00000004 /* turncate to 0 if file exists */
  144. #define LO_O_RDWR 0x00000008 /* read/write (default) */
  145. #define LO_O_RDONLY 0x00000010 /* read-only (from-flags only) */
  146. #define LO_O_WRONLY 0x00000020 /* write-only (to-flags only) */
  147. #define LO_O_BINARY 0x00000040 /* binary-mode (default) */
  148. #define LO_O_TEXT 0x00000080 /* text-mode (default off)*/
  149. /*******************************************************************************
  150. *
  151. * Smartblob Definitions
  152. *
  153. ******************************************************************************/
  154. /******************************************************************************
  155. * Open flags: see ESQL/C documentation for further explanation.
  156. *
  157. * LO_APPEND - Positions the seek position to end-of-file + 1. Affects write
  158. * operations. Reads can still seek anywhere in the LO. Writes always append.
  159. *
  160. * LO_SEQUENTIAL - If set overrides optimizer decision. Indicates that
  161. * reads are sequential in either forward or reverse direction.
  162. *
  163. * LO_RANDOM - If set overrides optimizer decision. Indicates that I/O is
  164. * random and that the system should not read-ahead.
  165. * LO_FORWARD - Only used for sequential access. Indicates that the sequential
  166. * access will be in a forward direction, i.e. from low offset to higher offset.
  167. * LO_REVERSE - Only used for sequential access. Indicates that the sequential
  168. * access will be in a reverse direction.
  169. *
  170. * LO_BUFFER - If set overrides optimizer decision. I/O goes through the
  171. * buffer pool. This is the "normal" case.
  172. *
  173. * LO_NOBUFFER - If set then I/O does not use the buffer pool. Instead the I/O
  174. * will use the light I/O private buffers.
  175. ******************************************************************************/
  176. #define LO_APPEND 0x1
  177. #define LO_WRONLY 0x2
  178. #define LO_RDONLY 0x4 /* default */
  179. #define LO_RDWR 0x8
  180. #define LO_DIRTY_READ 0x10
  181. #define LO_RANDOM 0x20 /* default is determined by optimizer */
  182. #define LO_SEQUENTIAL 0x40 /* default is determined by optimizer */
  183. #define LO_FORWARD 0x80 /* default */
  184. #define LO_REVERSE 0x100
  185. #define LO_BUFFER 0x200 /* default is determined by optimizer */
  186. #define LO_NOBUFFER 0x400 /* default is determined by optimizer */
  187. #define LO_NODIRTY_READ 0x800
  188. #define LO_LOCKALL 0x1000 /* default */
  189. #define LO_LOCKRANGE 0x2000
  190. #ifndef REMOVE_VECTORIO
  191. #define LO_VECTORIO 0x4000
  192. #endif
  193. #define LO_SECONDARY_NODE 0x8000 /* secondary node:not primary - sbmach11 */
  194. /*
  195. * LO_PSEUDO and LO_SNOOP pseudo-smartblob flags
  196. *
  197. * Subsytems other than the smartblob subsystem (notably, CDC transaction
  198. * capture and CDR, with other users to come) store entries in the
  199. * session's open-smartblob table. These entries are not actual smartblobs
  200. * (as implemented by tristarp/sblob), instead they simply use the
  201. * smartblob interface to access other sources of data, much as eg in Unix
  202. * an open file descriptor can refer to, say, a pipe or a file. LO_PSEUDO
  203. * and LO_SNOOP flags indicate such "not a real smartblob" entries.
  204. */
  205. #define LO_PSEUDO 0x00010000 /* This is a pseudo large object */
  206. #define LO_SNOOP 0x00020000 /* Pseudo-sblob entry for tx capture */
  207. #define LO_TRANSACTION_SURVIVAL 0x40000 /* This call is transaction survival */
  208. #define LO_PRIMARY_NODE 0x80000
  209. #define LO_PUSHDATA 0x00100000
  210. /* See sblob.h for the internal-use open flags list */
  211. /*
  212. * Another set of open flags are defined to make the flags more meaningful
  213. */
  214. #define LO_OPEN_APPEND LO_APPEND
  215. #define LO_OPEN_WRONLY LO_WRONLY
  216. #define LO_OPEN_RDONLY LO_RDONLY /* default */
  217. #define LO_OPEN_RDWR LO_RDWR
  218. #define LO_OPEN_DIRTY_READ LO_DIRTY_READ
  219. #define LO_OPEN_RANDOM LO_RANDOM /* default is determined by optimizer */
  220. #define LO_OPEN_SEQUENTIAL LO_SEQUENTIAL /* default is determined by optimizer */
  221. #define LO_OPEN_FORWARD LO_FORWARD /* default */
  222. #define LO_OPEN_REVERSE LO_REVERSE
  223. #define LO_OPEN_BUFFER LO_BUFFER /* default is determined by optimizer */
  224. #define LO_OPEN_NOBUFFER LO_NOBUFFER /* default is determined by optimizer */
  225. #define LO_OPEN_NODIRTY_READ LO_NODIRTY_READ
  226. #define LO_OPEN_LOCKALL LO_LOCKALL /* default */
  227. #define LO_OPEN_LOCKRANGE LO_LOCKRANGE
  228. /* When setting the MI_LO_NOBUFFER flag for write operations, please
  229. * don't set this flag if the object is small. It usually causes a synchronous
  230. * flush of the log and a synchronous flush of pages written - this is
  231. * very slow. Instead use buffered I/O for small writes.
  232. */
  233. #define LO_NOBUFFER_SIZE_THRESHOLD 8080
  234. /*see Informix internal use file /vobs/tristarp/incl/sblob.h for other flags*/
  235. /*******************************************************************************
  236. * LO create-time flags:
  237. *
  238. * Bitmask - Set/Get via ifx_lo_specset_flags() on ifx_lo_create_spec_t.
  239. *
  240. * New applications should use the flags which begin LO_ATTR_
  241. * The second set of flags are defined for backward compatibility only.
  242. ******************************************************************************/
  243. #define LO_ATTR_LOG 0x0001
  244. #define LO_ATTR_NOLOG 0x0002
  245. #define LO_ATTR_DELAY_LOG 0x0004
  246. #define LO_ATTR_KEEP_LASTACCESS_TIME 0x0008
  247. #define LO_ATTR_NOKEEP_LASTACCESS_TIME 0x0010
  248. #define LO_ATTR_HIGH_INTEG 0x0020
  249. #define LO_ATTR_MODERATE_INTEG 0x0040
  250. #define LO_ATTR_TEMP 0x0080
  251. /* these 7 values are defined for backward compatibility only */
  252. #define LO_LOG 0x0001
  253. #define LO_NOLOG 0x0002
  254. #define LO_DELAY_LOG 0x0004
  255. #define LO_KEEP_LASTACCESS_TIME 0x0008
  256. #define LO_NOKEEP_LASTACCESS_TIME 0x0010
  257. #define LO_HIGH_INTEG 0x0020
  258. #define LO_MODERATE_INTEG 0x0040
  259. #define LO_TEMP 0x0080
  260. #define LO_RELOCATED 0x0100 /* see comment below */
  261. #define LO_RELOCATED_PTR 0x0200
  262. /* these flags are defined to make the create flags more meaningful */
  263. #define LO_CREATE_LOG 0x0001
  264. #define LO_CREATE_NOLOG 0x0002
  265. #define LO_CREATE_DELAY_LOG 0x0004
  266. #define LO_CREATE_KEEP_LASTACCESS_TIME 0x0008
  267. #define LO_CREATE_NOKEEP_LASTACCESS_TIME 0x0010
  268. #define LO_CREATE_HIGH_INTEG 0x0020
  269. #define LO_CREATE_MODERATE_INTEG 0x0040
  270. #define LO_CREATE_TEMP 0x0080
  271. #define LO_CREATE_RELOCATED 0x0100 /* this LO was supposed
  272. * go into an occuppied row
  273. * mach11 */
  274. #define LO_CREATE_RELOCATED_PTR 0x0200 /* this LO points to a
  275. * relocated row - mach11 */
  276. #define LO_CREATE_CDR 0x0400 /* This LO is created by ER */
  277. /*******************************************************************************
  278. * Symbolic constants for the "lseek" routine
  279. ******************************************************************************/
  280. #define LO_SEEK_SET 0 /* Set curr. pos. to "offset" */
  281. #define LO_SEEK_CUR 1 /* Set curr. pos. to current + "offset" */
  282. #define LO_SEEK_END 2 /* Set curr. pos. to EOF + "offset" */
  283. #define LO_SEEK_PSEUDO 40 /* Read from pseudo large object */
  284. /*******************************************************************************
  285. * Symbolic constants for lo_lock and lo_unlock routines.
  286. ******************************************************************************/
  287. #define LO_SHARED_MODE 1 /* ISSLOCK */
  288. #define LO_EXCLUSIVE_MODE 2 /* ISXLOCK */
  289. #define LO_MAX_END -1
  290. #define LO_CURRENT_END -2
  291. /*******************************************************************************
  292. * ifx_lo_create_spec_t:
  293. *
  294. * This is an opaque structure used for creating smartblobs. The
  295. * user may examin and/or set certain fields herein by using
  296. * ifx_lo_spec[set|get]_* accessor functions. Prototypes for these acessors
  297. * are in incl/sqlhdr.h
  298. *
  299. ******************************************************************************/
  300. typedef struct ifx_lo_create_spec_s ifx_lo_create_spec_t;
  301. /*******************************************************************************
  302. * ifx_lo_t: A dummy opaque representation of the smartblob structure
  303. *
  304. * This can be used for stack or in-line structure declarations.
  305. *
  306. ******************************************************************************/
  307. #define SB_LOCSIZE 72 /* length of ifx_lo_t */
  308. typedef struct ifx_lo_ts
  309. {
  310. char dummy[SB_LOCSIZE];
  311. } ifx_lo_t;
  312. /*******************************************************************************
  313. * ifx_lo_stat:
  314. *
  315. * This is an opaque structure used in querying attribtes of smartblobs. The
  316. * user may examin fields herein by using ifx_lo_stat_* accessor functions.
  317. * Prototypes for these acessors are in incl/sqlhdr.h
  318. *
  319. * The accessors are defined as follows:
  320. * ifx_lo_stat_size: contains the size of the LO in bytes.
  321. * ifx_lo_stat_uid: reserved for future use: the user id for the
  322. * owner of the LO.
  323. * ifx_lo_stat_atime: the time of last access. This is only maintained if
  324. * the LO_KEEP_LASTACCESS_TIME flag is set for the LO.
  325. * Resolution is seconds.
  326. * ifx_lo_stat_mtime: the time of last modification. Resolution is
  327. * seconds.
  328. * ifx_lo_stat_ctime: the time of the last status change (this includes
  329. * updates, changes in ownership, and changes to the number of
  330. * references). Resolution is seconds. See Appendix B2.11,
  331. * Future Embedded- language feature issues, Smartblob API
  332. * functions using lofd, for enhancements that extend support
  333. * for named and external LOs.
  334. * ifx_lo_stat_refcnt: the number of pointers to this LO - when 0 the LO is
  335. * typically deleted. See deletion criteria.
  336. * ifx_lo_stat_cspec: a pointer to the opaque create spec for this object.
  337. * (see ifx_lo_spec[get|set]_ accessors for details.)
  338. * ifx_lo_stat_type: the 8 byte code for the LO's type
  339. *
  340. ******************************************************************************/
  341. typedef struct ifx_lo_stat_s ifx_lo_stat_t;
  342. #endif /* LOCATOR_INCL */