Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

4369 lines
148 KiB

  1. /***************************************************************************/
  2. /* SCALAR.CPP */
  3. /* Copyright (C) 1997 SYWARE Inc., All rights reserved */
  4. /***************************************************************************/
  5. // Commenting #define out - causing compiler error - not sure if needed, compiles
  6. // okay without it.
  7. //#define WINVER 0x0400
  8. #include "precomp.h"
  9. #include "wbemidl.h"
  10. #include <comdef.h>
  11. //smart pointer
  12. _COM_SMARTPTR_TYPEDEF(IWbemServices, IID_IWbemServices);
  13. _COM_SMARTPTR_TYPEDEF(IEnumWbemClassObject, IID_IEnumWbemClassObject);
  14. //_COM_SMARTPTR_TYPEDEF(IWbemContext, IID_IWbemContext );
  15. _COM_SMARTPTR_TYPEDEF(IWbemLocator, IID_IWbemLocator);
  16. #include "drdbdr.h"
  17. #include <math.h>
  18. #include <stdlib.h>
  19. #ifndef WIN32
  20. #include <signal.h>
  21. #include <setjmp.h>
  22. #include <float.h>
  23. #endif
  24. #include <time.h>
  25. #ifndef WIN32
  26. #ifdef __cplusplus
  27. #define _JBLEN 9
  28. #ifndef _JMP_BUF_DEFINED
  29. typedef int jmp_buf[_JBLEN];
  30. #define _JMP_BUF_DEFINED
  31. #endif
  32. #define setjmp _setjmp
  33. extern "C" {
  34. int __cdecl _setjmp(jmp_buf);
  35. void __cdecl longjmp(jmp_buf, int);
  36. }
  37. #endif
  38. jmp_buf scalarExceptionMark;
  39. #endif
  40. #define MAX_SCALAR_ARGS 4
  41. typedef struct tagSCALARFUNC {
  42. LPUSTR name; /* Name of the scalar function */
  43. SWORD dataType; /* Data type returned (TYPE_*) */
  44. SWORD sqlType; /* Sql type returned (SQL_*) (use SQL_* of */
  45. /* first argument if SQL_TYPE_NULL) */
  46. SDWORD precision; /* Precision (use precision of first */
  47. /* argument if 0) */
  48. SWORD scale; /* Scale if sqlType is SQL_DECIMAL */
  49. /* or SQL_NUMERIC (use scale of first */
  50. /* argument if precision is 0 */
  51. UWORD argCount; /* Number of argments */
  52. SWORD argType[MAX_SCALAR_ARGS]; /* Data typeof each arg (TYPE_*) */
  53. } SCALARFUNC,
  54. FAR *LPSCALARFUNC;
  55. #define SCALAR_ASCII 0
  56. #define SCALAR_CHAR 1
  57. #define SCALAR_CONCAT 2
  58. #define SCALAR_DIFFERENCE 3
  59. #define SCALAR_INSERT 4
  60. #define SCALAR_LCASE 5
  61. #define SCALAR_LEFT 6
  62. #define SCALAR_LENGTH 7
  63. #define SCALAR_LOCATE 8
  64. #define SCALAR_LOCATE_START 9
  65. #define SCALAR_LTRIM 10
  66. #define SCALAR_REPEAT 11
  67. #define SCALAR_REPLACE 12
  68. #define SCALAR_RIGHT 13
  69. #define SCALAR_RTRIM 14
  70. #define SCALAR_SOUNDEX 15
  71. #define SCALAR_SPACE 16
  72. #define SCALAR_SUBSTRING 17
  73. #define SCALAR_UCASE 18
  74. #define SCALAR_ABS_DOUBLE 19
  75. #define SCALAR_ABS_NUMERIC 20
  76. #define SCALAR_ABS_INTEGER 21
  77. #define SCALAR_ACOS 22
  78. #define SCALAR_ASIN 23
  79. #define SCALAR_ATAN 24
  80. #define SCALAR_ATAN2 25
  81. #define SCALAR_CEILING_DOUBLE 26
  82. #define SCALAR_CEILING_NUMERIC 27
  83. #define SCALAR_CEILING_INTEGER 28
  84. #define SCALAR_COS 29
  85. #define SCALAR_COT 30
  86. #define SCALAR_DEGREES_DOUBLE 31
  87. #define SCALAR_DEGREES_NUMERIC 32
  88. #define SCALAR_DEGREES_INTEGER 33
  89. #define SCALAR_EXP 34
  90. #define SCALAR_FLOOR_DOUBLE 35
  91. #define SCALAR_FLOOR_NUMERIC 36
  92. #define SCALAR_FLOOR_INTEGER 37
  93. #define SCALAR_LOG 38
  94. #define SCALAR_LOG10 39
  95. #define SCALAR_MOD 40
  96. #define SCALAR_PI 41
  97. #define SCALAR_POWER_DOUBLE 42
  98. #define SCALAR_POWER_NUMERIC 43
  99. #define SCALAR_POWER_INTEGER 44
  100. #define SCALAR_RADIANS_DOUBLE 45
  101. #define SCALAR_RADIANS_NUMERIC 46
  102. #define SCALAR_RADIANS_INTEGER 47
  103. #define SCALAR_RAND 48
  104. #define SCALAR_RAND_SEED_DOUBLE 49
  105. #define SCALAR_RAND_SEED_NUMERIC 50
  106. #define SCALAR_RAND_SEED_INTEGER 51
  107. #define SCALAR_ROUND_DOUBLE 52
  108. #define SCALAR_ROUND_NUMERIC 53
  109. #define SCALAR_ROUND_INTEGER 54
  110. #define SCALAR_SIGN_DOUBLE 55
  111. #define SCALAR_SIGN_NUMERIC 56
  112. #define SCALAR_SIGN_INTEGER 57
  113. #define SCALAR_SIN 58
  114. #define SCALAR_SQRT 59
  115. #define SCALAR_TAN 60
  116. #define SCALAR_TRUNCATE_DOUBLE 61
  117. #define SCALAR_TRUNCATE_NUMERIC 62
  118. #define SCALAR_TRUNCATE_INTEGER 63
  119. #define SCALAR_CURDATE 64
  120. #define SCALAR_CURTIME 65
  121. #define SCALAR_DAYNAME 66
  122. #define SCALAR_DAYOFMONTH_CHAR 67
  123. #define SCALAR_DAYOFMONTH_DATE 68
  124. #define SCALAR_DAYOFMONTH_TIMESTAMP 69
  125. #define SCALAR_DAYOFWEEK 70
  126. #define SCALAR_DAYOFYEAR 71
  127. #define SCALAR_HOUR_CHAR 72
  128. #define SCALAR_HOUR_TIME 73
  129. #define SCALAR_HOUR_TIMESTAMP 74
  130. #define SCALAR_MINUTE_CHAR 75
  131. #define SCALAR_MINUTE_TIME 76
  132. #define SCALAR_MINUTE_TIMESTAMP 77
  133. #define SCALAR_MONTH_CHAR 78
  134. #define SCALAR_MONTH_DATE 79
  135. #define SCALAR_MONTH_TIMESTAMP 80
  136. #define SCALAR_MONTHNAME_CHAR 81
  137. #define SCALAR_MONTHNAME_DATE 82
  138. #define SCALAR_MONTHNAME_TIMESTAMP 83
  139. #define SCALAR_NOW 84
  140. #define SCALAR_QUARTER_CHAR 85
  141. #define SCALAR_QUARTER_DATE 86
  142. #define SCALAR_QUARTER_TIMESTAMP 87
  143. #define SCALAR_SECOND_CHAR 88
  144. #define SCALAR_SECOND_TIME 89
  145. #define SCALAR_SECOND_TIMESTAMP 90
  146. #define SCALAR_TIMESTAMPADD 91
  147. #define SCALAR_TIMESTAMPDIFF 92
  148. #define SCALAR_WEEK 93
  149. #define SCALAR_YEAR_CHAR 94
  150. #define SCALAR_YEAR_DATE 95
  151. #define SCALAR_YEAR_TIMESTAMP 96
  152. #define SCALAR_DATABASE 97
  153. #define SCALAR_IFNULL 98
  154. #define SCALAR_USER 99
  155. #define SCALAR_CONVERT 100
  156. /* Seed value for SCALAR_RAND_* functions */
  157. static long new_seed = 1;
  158. SCALARFUNC scalarFuncs[] = {
  159. /* SCALAR_ASCII */
  160. {
  161. /* name */ (LPUSTR) "ASCII",
  162. /* dataType */ TYPE_INTEGER,
  163. /* sqlType */ SQL_TINYINT,
  164. /* precision */ 3,
  165. /* scale */ 0,
  166. /* argCount */ 1,
  167. /* argType[] */ { TYPE_CHAR }
  168. },
  169. /* SCALAR_CHAR */
  170. {
  171. /* name */ (LPUSTR) "CHAR",
  172. /* dataType */ TYPE_CHAR,
  173. /* sqlType */ SQL_VARCHAR,
  174. /* precision */ 1,
  175. /* scale */ 0,
  176. /* argCount */ 1,
  177. /* argType[] */ { TYPE_INTEGER }
  178. },
  179. /* SCALAR_CONCAT */
  180. {
  181. /* name */ (LPUSTR) "CONCAT",
  182. /* dataType */ TYPE_CHAR,
  183. /* sqlType */ SQL_VARCHAR,
  184. /* precision */ 0,
  185. /* scale */ 0,
  186. /* argCount */ 2,
  187. /* argType[] */ { TYPE_CHAR, TYPE_CHAR }
  188. },
  189. /* SCALAR_DIFFERENCE */
  190. {
  191. /* name */ (LPUSTR) "DIFFERENCE",
  192. /* dataType */ TYPE_INTEGER,
  193. /* sqlType */ SQL_INTEGER,
  194. /* precision */ 10,
  195. /* scale */ 0,
  196. /* argCount */ 2,
  197. /* argType[] */ { TYPE_CHAR, TYPE_CHAR }
  198. },
  199. /* SCALAR_INSERT_INTEGER */
  200. {
  201. /* name */ (LPUSTR) "INSERT",
  202. /* dataType */ TYPE_CHAR,
  203. /* sqlType */ SQL_VARCHAR,
  204. /* precision */ MAX_CHAR_LITERAL_LENGTH,
  205. /* scale */ 0,
  206. /* argCount */ 4,
  207. /* argType[] */ { TYPE_CHAR, TYPE_INTEGER, TYPE_INTEGER, TYPE_CHAR }
  208. },
  209. /* SCALAR_LCASE */
  210. {
  211. /* name */ (LPUSTR) "LCASE",
  212. /* dataType */ TYPE_CHAR,
  213. /* sqlType */ SQL_TYPE_NULL,
  214. /* precision */ 0,
  215. /* scale */ 0,
  216. /* argCount */ 1,
  217. /* argType[] */ { TYPE_CHAR }
  218. },
  219. /* SCALAR_LEFT */
  220. {
  221. /* name */ (LPUSTR) "LEFT",
  222. /* dataType */ TYPE_CHAR,
  223. /* sqlType */ SQL_VARCHAR,
  224. /* precision */ 0,
  225. /* scale */ 0,
  226. /* argCount */ 2,
  227. /* argType[] */ { TYPE_CHAR, TYPE_INTEGER }
  228. },
  229. /* SCALAR_LENGTH */
  230. {
  231. /* name */ (LPUSTR) "LENGTH",
  232. /* dataType */ TYPE_INTEGER,
  233. /* sqlType */ SQL_SMALLINT,
  234. /* precision */ 5,
  235. /* scale */ 0,
  236. /* argCount */ 1,
  237. /* argType[] */ { TYPE_CHAR }
  238. },
  239. /* SCALAR_LOCATE */
  240. {
  241. /* name */ (LPUSTR) "LOCATE",
  242. /* dataType */ TYPE_INTEGER,
  243. /* sqlType */ SQL_SMALLINT,
  244. /* precision */ 5,
  245. /* scale */ 0,
  246. /* argCount */ 2,
  247. /* argType[] */ { TYPE_CHAR, TYPE_CHAR }
  248. },
  249. /* SCALAR_LOCATE_START */
  250. {
  251. /* name */ (LPUSTR) "LOCATE",
  252. /* dataType */ TYPE_INTEGER,
  253. /* sqlType */ SQL_SMALLINT,
  254. /* precision */ 5,
  255. /* scale */ 0,
  256. /* argCount */ 3,
  257. /* argType[] */ { TYPE_CHAR, TYPE_CHAR, TYPE_INTEGER }
  258. },
  259. /* SCALAR_LTRIM */
  260. {
  261. /* name */ (LPUSTR) "LTRIM",
  262. /* dataType */ TYPE_CHAR,
  263. /* sqlType */ SQL_VARCHAR,
  264. /* precision */ 0,
  265. /* scale */ 0,
  266. /* argCount */ 1,
  267. /* argType[] */ { TYPE_CHAR }
  268. },
  269. /* SCALAR_REPEAT */
  270. {
  271. /* name */ (LPUSTR) "REPEAT",
  272. /* dataType */ TYPE_CHAR,
  273. /* sqlType */ SQL_VARCHAR,
  274. /* precision */ MAX_CHAR_LITERAL_LENGTH,
  275. /* scale */ 0,
  276. /* argCount */ 2,
  277. /* argType[] */ { TYPE_CHAR, TYPE_INTEGER }
  278. },
  279. /* SCALAR_REPLACE */
  280. {
  281. /* name */ (LPUSTR) "REPLACE",
  282. /* dataType */ TYPE_CHAR,
  283. /* sqlType */ SQL_VARCHAR,
  284. /* precision */ MAX_CHAR_LITERAL_LENGTH,
  285. /* scale */ 0,
  286. /* argCount */ 3,
  287. /* argType[] */ { TYPE_CHAR, TYPE_CHAR, TYPE_CHAR }
  288. },
  289. /* SCALAR_RIGHT */
  290. {
  291. /* name */ (LPUSTR) "RIGHT",
  292. /* dataType */ TYPE_CHAR,
  293. /* sqlType */ SQL_VARCHAR,
  294. /* precision */ 0,
  295. /* scale */ 0,
  296. /* argCount */ 2,
  297. /* argType[] */ { TYPE_CHAR, TYPE_INTEGER }
  298. },
  299. /* SCALAR_RTRIM */
  300. {
  301. /* name */ (LPUSTR) "RTRIM",
  302. /* dataType */ TYPE_CHAR,
  303. /* sqlType */ SQL_VARCHAR,
  304. /* precision */ 0,
  305. /* scale */ 0,
  306. /* argCount */ 1,
  307. /* argType[] */ { TYPE_CHAR }
  308. },
  309. /* SCALAR_SOUNDEX */
  310. {
  311. /* name */ (LPUSTR) "SOUNDEX",
  312. /* dataType */ TYPE_CHAR,
  313. /* sqlType */ SQL_VARCHAR,
  314. /* precision */ MAX_CHAR_LITERAL_LENGTH,
  315. /* scale */ 0,
  316. /* argCount */ 1,
  317. /* argType[] */ { TYPE_CHAR }
  318. },
  319. /* SCALAR_SPACE */
  320. {
  321. /* name */ (LPUSTR) "SPACE",
  322. /* dataType */ TYPE_CHAR,
  323. /* sqlType */ SQL_VARCHAR,
  324. /* precision */ MAX_CHAR_LITERAL_LENGTH,
  325. /* scale */ 0,
  326. /* argCount */ 1,
  327. /* argType[] */ { TYPE_INTEGER }
  328. },
  329. /* SCALAR_SUBSTRING */
  330. {
  331. /* name */ (LPUSTR) "SUBSTRING",
  332. /* dataType */ TYPE_CHAR,
  333. /* sqlType */ SQL_VARCHAR,
  334. /* precision */ 0,
  335. /* scale */ 0,
  336. /* argCount */ 3,
  337. /* argType[] */ { TYPE_CHAR, TYPE_INTEGER, TYPE_INTEGER }
  338. },
  339. /* SCALAR_UCASE */
  340. {
  341. /* name */ (LPUSTR) "UCASE",
  342. /* dataType */ TYPE_CHAR,
  343. /* sqlType */ SQL_TYPE_NULL,
  344. /* precision */ 0,
  345. /* scale */ 0,
  346. /* argCount */ 1,
  347. /* argType[] */ { TYPE_CHAR }
  348. },
  349. /* SCALAR_ABS_DOUBLE */
  350. {
  351. /* name */ (LPUSTR) "ABS",
  352. /* dataType */ TYPE_DOUBLE,
  353. /* sqlType */ SQL_TYPE_NULL,
  354. /* precision */ 0,
  355. /* scale */ 0,
  356. /* argCount */ 1,
  357. /* argType[] */ { TYPE_DOUBLE }
  358. },
  359. /* SCALAR_ABS_NUMERIC */
  360. {
  361. /* name */ (LPUSTR) "ABS",
  362. /* dataType */ TYPE_NUMERIC,
  363. /* sqlType */ SQL_TYPE_NULL,
  364. /* precision */ 0,
  365. /* scale */ 0,
  366. /* argCount */ 1,
  367. /* argType[] */ { TYPE_NUMERIC }
  368. },
  369. /* SCALAR_ABS_INTEGER */
  370. {
  371. /* name */ (LPUSTR) "ABS",
  372. /* dataType */ TYPE_INTEGER,
  373. /* sqlType */ SQL_TYPE_NULL,
  374. /* precision */ 0,
  375. /* scale */ 0,
  376. /* argCount */ 1,
  377. /* argType[] */ { TYPE_INTEGER }
  378. },
  379. /* SCALAR_ACOS */
  380. {
  381. /* name */ (LPUSTR) "ACOS",
  382. /* dataType */ TYPE_DOUBLE,
  383. /* sqlType */ SQL_DOUBLE,
  384. /* precision */ 15,
  385. /* scale */ NO_SCALE,
  386. /* argCount */ 1,
  387. /* argType[] */ { TYPE_DOUBLE }
  388. },
  389. /* SCALAR_ASIN */
  390. {
  391. /* name */ (LPUSTR) "ASIN",
  392. /* dataType */ TYPE_DOUBLE,
  393. /* sqlType */ SQL_DOUBLE,
  394. /* precision */ 15,
  395. /* scale */ NO_SCALE,
  396. /* argCount */ 1,
  397. /* argType[] */ { TYPE_DOUBLE }
  398. },
  399. /* SCALAR_ATAN */
  400. {
  401. /* name */ (LPUSTR) "ATAN",
  402. /* dataType */ TYPE_DOUBLE,
  403. /* sqlType */ SQL_DOUBLE,
  404. /* precision */ 15,
  405. /* scale */ NO_SCALE,
  406. /* argCount */ 1,
  407. /* argType[] */ { TYPE_DOUBLE }
  408. },
  409. /* SCALAR_ATAN2 */
  410. {
  411. /* name */ (LPUSTR) "ATAN2",
  412. /* dataType */ TYPE_DOUBLE,
  413. /* sqlType */ SQL_DOUBLE,
  414. /* precision */ 15,
  415. /* scale */ NO_SCALE,
  416. /* argCount */ 2,
  417. /* argType[] */ { TYPE_DOUBLE, TYPE_DOUBLE }
  418. },
  419. /* SCALAR_CEILING_DOUBLE */
  420. {
  421. /* name */ (LPUSTR) "CEILING",
  422. /* dataType */ TYPE_DOUBLE,
  423. /* sqlType */ SQL_TYPE_NULL,
  424. /* precision */ 0,
  425. /* scale */ 0,
  426. /* argCount */ 1,
  427. /* argType[] */ { TYPE_DOUBLE }
  428. },
  429. /* SCALAR_CEILING_NUMERIC */
  430. {
  431. /* name */ (LPUSTR) "CEILING",
  432. /* dataType */ TYPE_NUMERIC,
  433. /* sqlType */ SQL_TYPE_NULL,
  434. /* precision */ 0,
  435. /* scale */ 0,
  436. /* argCount */ 1,
  437. /* argType[] */ { TYPE_NUMERIC }
  438. },
  439. /* SCALAR_CEILING_INTEGER */
  440. {
  441. /* name */ (LPUSTR) "CEILING",
  442. /* dataType */ TYPE_INTEGER,
  443. /* sqlType */ SQL_TYPE_NULL,
  444. /* precision */ 0,
  445. /* scale */ 0,
  446. /* argCount */ 1,
  447. /* argType[] */ { TYPE_INTEGER }
  448. },
  449. /* SCALAR_COS */
  450. {
  451. /* name */ (LPUSTR) "COS",
  452. /* dataType */ TYPE_DOUBLE,
  453. /* sqlType */ SQL_DOUBLE,
  454. /* precision */ 15,
  455. /* scale */ NO_SCALE,
  456. /* argCount */ 1,
  457. /* argType[] */ { TYPE_DOUBLE }
  458. },
  459. /* SCALAR_COT */
  460. {
  461. /* name */ (LPUSTR) "COT",
  462. /* dataType */ TYPE_DOUBLE,
  463. /* sqlType */ SQL_DOUBLE,
  464. /* precision */ 15,
  465. /* scale */ NO_SCALE,
  466. /* argCount */ 1,
  467. /* argType[] */ { TYPE_DOUBLE }
  468. },
  469. /* SCALAR_DEGREES_DOUBLE */
  470. {
  471. /* name */ (LPUSTR) "DEGREES",
  472. /* dataType */ TYPE_DOUBLE,
  473. /* sqlType */ SQL_DOUBLE,
  474. /* precision */ 15,
  475. /* scale */ NO_SCALE,
  476. /* argCount */ 1,
  477. /* argType[] */ { TYPE_DOUBLE }
  478. },
  479. /* SCALAR_DEGREES_NUMERIC */
  480. {
  481. /* name */ (LPUSTR) "DEGREES",
  482. /* dataType */ TYPE_DOUBLE,
  483. /* sqlType */ SQL_DOUBLE,
  484. /* precision */ 15,
  485. /* scale */ NO_SCALE,
  486. /* argCount */ 1,
  487. /* argType[] */ { TYPE_NUMERIC }
  488. },
  489. /* SCALAR_DEGREES_INTEGER */
  490. {
  491. /* name */ (LPUSTR) "DEGREES",
  492. /* dataType */ TYPE_DOUBLE,
  493. /* sqlType */ SQL_DOUBLE,
  494. /* precision */ 15,
  495. /* scale */ NO_SCALE,
  496. /* argCount */ 1,
  497. /* argType[] */ { TYPE_INTEGER }
  498. },
  499. /* SCALAR_EXP */
  500. {
  501. /* name */ (LPUSTR) "EXP",
  502. /* dataType */ TYPE_DOUBLE,
  503. /* sqlType */ SQL_DOUBLE,
  504. /* precision */ 15,
  505. /* scale */ NO_SCALE,
  506. /* argCount */ 1,
  507. /* argType[] */ { TYPE_DOUBLE }
  508. },
  509. /* SCALAR_FLOOR_DOUBLE */
  510. {
  511. /* name */ (LPUSTR) "FLOOR",
  512. /* dataType */ TYPE_DOUBLE,
  513. /* sqlType */ SQL_TYPE_NULL,
  514. /* precision */ 0,
  515. /* scale */ 0,
  516. /* argCount */ 1,
  517. /* argType[] */ { TYPE_DOUBLE }
  518. },
  519. /* SCALAR_FLOOR_NUMERIC */
  520. {
  521. /* name */ (LPUSTR) "FLOOR",
  522. /* dataType */ TYPE_NUMERIC,
  523. /* sqlType */ SQL_TYPE_NULL,
  524. /* precision */ 0,
  525. /* scale */ 0,
  526. /* argCount */ 1,
  527. /* argType[] */ { TYPE_NUMERIC }
  528. },
  529. /* SCALAR_FLOOR_INTEGER */
  530. {
  531. /* name */ (LPUSTR) "FLOOR",
  532. /* dataType */ TYPE_INTEGER,
  533. /* sqlType */ SQL_TYPE_NULL,
  534. /* precision */ 0,
  535. /* scale */ 0,
  536. /* argCount */ 1,
  537. /* argType[] */ { TYPE_INTEGER }
  538. },
  539. /* SCALAR_LOG */
  540. {
  541. /* name */ (LPUSTR) "LOG",
  542. /* dataType */ TYPE_DOUBLE,
  543. /* sqlType */ SQL_DOUBLE,
  544. /* precision */ 15,
  545. /* scale */ NO_SCALE,
  546. /* argCount */ 1,
  547. /* argType[] */ { TYPE_DOUBLE }
  548. },
  549. /* SCALAR_LOG10 */
  550. {
  551. /* name */ (LPUSTR) "LOG10",
  552. /* dataType */ TYPE_DOUBLE,
  553. /* sqlType */ SQL_DOUBLE,
  554. /* precision */ 15,
  555. /* scale */ NO_SCALE,
  556. /* argCount */ 1,
  557. /* argType[] */ { TYPE_DOUBLE }
  558. },
  559. /* SCALAR_MOD */
  560. {
  561. /* name */ (LPUSTR) "MOD",
  562. /* dataType */ TYPE_INTEGER,
  563. /* sqlType */ SQL_TYPE_NULL,
  564. /* precision */ 0,
  565. /* scale */ 0,
  566. /* argCount */ 2,
  567. /* argType[] */ { TYPE_INTEGER, TYPE_INTEGER }
  568. },
  569. /* SCALAR_PI */
  570. {
  571. /* name */ (LPUSTR) "PI",
  572. /* dataType */ TYPE_DOUBLE,
  573. /* sqlType */ SQL_DOUBLE,
  574. /* precision */ 15,
  575. /* scale */ NO_SCALE,
  576. /* argCount */ 0
  577. },
  578. /* SCALAR_POWER_DOUBLE */
  579. {
  580. /* name */ (LPUSTR) "POWER",
  581. /* dataType */ TYPE_DOUBLE,
  582. /* sqlType */ SQL_DOUBLE,
  583. /* precision */ 15,
  584. /* scale */ NO_SCALE,
  585. /* argCount */ 2,
  586. /* argType[] */ { TYPE_DOUBLE, TYPE_INTEGER }
  587. },
  588. /* SCALAR_POWER_NUMERIC */
  589. {
  590. /* name */ (LPUSTR) "POWER",
  591. /* dataType */ TYPE_DOUBLE,
  592. /* sqlType */ SQL_DOUBLE,
  593. /* precision */ 15,
  594. /* scale */ NO_SCALE,
  595. /* argCount */ 2,
  596. /* argType[] */ { TYPE_NUMERIC, TYPE_INTEGER }
  597. },
  598. /* SCALAR_POWER_INTEGER */
  599. {
  600. /* name */ (LPUSTR) "POWER",
  601. /* dataType */ TYPE_DOUBLE,
  602. /* sqlType */ SQL_DOUBLE,
  603. /* precision */ 15,
  604. /* scale */ NO_SCALE,
  605. /* argCount */ 2,
  606. /* argType[] */ { TYPE_INTEGER, TYPE_INTEGER }
  607. },
  608. /* SCALAR_RADIANS_DOUBLE */
  609. {
  610. /* name */ (LPUSTR) "RADIANS",
  611. /* dataType */ TYPE_DOUBLE,
  612. /* sqlType */ SQL_DOUBLE,
  613. /* precision */ 15,
  614. /* scale */ NO_SCALE,
  615. /* argCount */ 1,
  616. /* argType[] */ { TYPE_DOUBLE }
  617. },
  618. /* SCALAR_RADIANS_NUMERIC */
  619. {
  620. /* name */ (LPUSTR) "RADIANS",
  621. /* dataType */ TYPE_DOUBLE,
  622. /* sqlType */ SQL_DOUBLE,
  623. /* precision */ 15,
  624. /* scale */ NO_SCALE,
  625. /* argCount */ 1,
  626. /* argType[] */ { TYPE_NUMERIC }
  627. },
  628. /* SCALAR_RADIANS_INTEGER */
  629. {
  630. /* name */ (LPUSTR) "RADIANS",
  631. /* dataType */ TYPE_DOUBLE,
  632. /* sqlType */ SQL_DOUBLE,
  633. /* precision */ 15,
  634. /* scale */ NO_SCALE,
  635. /* argCount */ 1,
  636. /* argType[] */ { TYPE_INTEGER }
  637. },
  638. /* SCALAR_RAND */
  639. {
  640. /* name */ (LPUSTR) "RAND",
  641. /* dataType */ TYPE_DOUBLE,
  642. /* sqlType */ SQL_DOUBLE,
  643. /* precision */ 15,
  644. /* scale */ NO_SCALE,
  645. /* argCount */ 0
  646. },
  647. /* SCALAR_RAND_SEED_DOUBLE */
  648. {
  649. /* name */ (LPUSTR) "RAND",
  650. /* dataType */ TYPE_DOUBLE,
  651. /* sqlType */ SQL_DOUBLE,
  652. /* precision */ 15,
  653. /* scale */ NO_SCALE,
  654. /* argCount */ 1,
  655. /* argType[] */ { TYPE_DOUBLE }
  656. },
  657. /* SCALAR_RAND_SEED_NUMERIC */
  658. {
  659. /* name */ (LPUSTR) "RAND",
  660. /* dataType */ TYPE_DOUBLE,
  661. /* sqlType */ SQL_DOUBLE,
  662. /* precision */ 15,
  663. /* scale */ NO_SCALE,
  664. /* argCount */ 1,
  665. /* argType[] */ { TYPE_NUMERIC }
  666. },
  667. /* SCALAR_RAND_SEED_INTEGER */
  668. {
  669. /* name */ (LPUSTR) "RAND",
  670. /* dataType */ TYPE_DOUBLE,
  671. /* sqlType */ SQL_DOUBLE,
  672. /* precision */ 15,
  673. /* scale */ NO_SCALE,
  674. /* argCount */ 1,
  675. /* argType[] */ { TYPE_INTEGER }
  676. },
  677. /* SCALAR_ROUND_DOUBLE */
  678. {
  679. /* name */ (LPUSTR) "ROUND",
  680. /* dataType */ TYPE_DOUBLE,
  681. /* sqlType */ SQL_TYPE_NULL,
  682. /* precision */ 0,
  683. /* scale */ 0,
  684. /* argCount */ 2,
  685. /* argType[] */ { TYPE_DOUBLE, TYPE_INTEGER }
  686. },
  687. /* SCALAR_ROUND_NUMERIC */
  688. {
  689. /* name */ (LPUSTR) "ROUND",
  690. /* dataType */ TYPE_NUMERIC,
  691. /* sqlType */ SQL_TYPE_NULL,
  692. /* precision */ 0,
  693. /* scale */ 0,
  694. /* argCount */ 2,
  695. /* argType[] */ { TYPE_NUMERIC, TYPE_INTEGER }
  696. },
  697. /* SCALAR_ROUND_INTEGER */
  698. {
  699. /* name */ (LPUSTR) "ROUND",
  700. /* dataType */ TYPE_INTEGER,
  701. /* sqlType */ SQL_TYPE_NULL,
  702. /* precision */ 0,
  703. /* scale */ 0,
  704. /* argCount */ 2,
  705. /* argType[] */ { TYPE_INTEGER, TYPE_INTEGER }
  706. },
  707. /* SCALAR_SIGN_DOUBLE */
  708. {
  709. /* name */ (LPUSTR) "SIGN",
  710. /* dataType */ TYPE_INTEGER,
  711. /* sqlType */ SQL_TINYINT,
  712. /* precision */ 3,
  713. /* scale */ 0,
  714. /* argCount */ 1,
  715. /* argType[] */ { TYPE_DOUBLE }
  716. },
  717. /* SCALAR_SIGN_NUMERIC */
  718. {
  719. /* name */ (LPUSTR) "SIGN",
  720. /* dataType */ TYPE_INTEGER,
  721. /* sqlType */ SQL_TINYINT,
  722. /* precision */ 3,
  723. /* scale */ 0,
  724. /* argCount */ 1,
  725. /* argType[] */ { TYPE_NUMERIC }
  726. },
  727. /* SCALAR_SIGN_INTEGER */
  728. {
  729. /* name */ (LPUSTR) "SIGN",
  730. /* dataType */ TYPE_INTEGER,
  731. /* sqlType */ SQL_TINYINT,
  732. /* precision */ 3,
  733. /* scale */ 0,
  734. /* argCount */ 1,
  735. /* argType[] */ { TYPE_INTEGER }
  736. },
  737. /* SCALAR_SIN */
  738. {
  739. /* name */ (LPUSTR) "SIN",
  740. /* dataType */ TYPE_DOUBLE,
  741. /* sqlType */ SQL_DOUBLE,
  742. /* precision */ 15,
  743. /* scale */ NO_SCALE,
  744. /* argCount */ 1,
  745. /* argType[] */ { TYPE_DOUBLE }
  746. },
  747. /* SCALAR_SQRT */
  748. {
  749. /* name */ (LPUSTR) "SQRT",
  750. /* dataType */ TYPE_DOUBLE,
  751. /* sqlType */ SQL_DOUBLE,
  752. /* precision */ 15,
  753. /* scale */ NO_SCALE,
  754. /* argCount */ 1,
  755. /* argType[] */ { TYPE_DOUBLE }
  756. },
  757. /* SCALAR_TAN */
  758. {
  759. /* name */ (LPUSTR) "TAN",
  760. /* dataType */ TYPE_DOUBLE,
  761. /* sqlType */ SQL_DOUBLE,
  762. /* precision */ 15,
  763. /* scale */ NO_SCALE,
  764. /* argCount */ 1,
  765. /* argType[] */ { TYPE_DOUBLE }
  766. },
  767. /* SCALAR_TRUNCATE_DOUBLE */
  768. {
  769. /* name */ (LPUSTR) "TRUNCATE",
  770. /* dataType */ TYPE_DOUBLE,
  771. /* sqlType */ SQL_TYPE_NULL,
  772. /* precision */ 0,
  773. /* scale */ 0,
  774. /* argCount */ 2,
  775. /* argType[] */ { TYPE_DOUBLE, TYPE_INTEGER }
  776. },
  777. /* SCALAR_TRUNCATE_NUMERIC */
  778. {
  779. /* name */ (LPUSTR) "TRUNCATE",
  780. /* dataType */ TYPE_NUMERIC,
  781. /* sqlType */ SQL_TYPE_NULL,
  782. /* precision */ 0,
  783. /* scale */ 0,
  784. /* argCount */ 2,
  785. /* argType[] */ { TYPE_NUMERIC, TYPE_INTEGER }
  786. },
  787. /* SCALAR_TRUNCATE_INTEGER */
  788. {
  789. /* name */ (LPUSTR) "TRUNCATE",
  790. /* dataType */ TYPE_INTEGER,
  791. /* sqlType */ SQL_TYPE_NULL,
  792. /* precision */ 0,
  793. /* scale */ 0,
  794. /* argCount */ 2,
  795. /* argType[] */ { TYPE_INTEGER, TYPE_INTEGER }
  796. },
  797. /* SCALAR_CURDATE */
  798. {
  799. /* name */ (LPUSTR) "CURDATE",
  800. /* dataType */ TYPE_DATE,
  801. /* sqlType */ SQL_TIMESTAMP, //SQL_DATE,
  802. /* precision */ 10,
  803. /* scale */ NO_SCALE,
  804. /* argCount */ 0
  805. },
  806. /* SCALAR_CURTIME */
  807. {
  808. /* name */ (LPUSTR) "CURTIME",
  809. /* dataType */ TYPE_TIME,
  810. /* sqlType */ SQL_TIMESTAMP, //SQL_TIME,
  811. /* precision */ 8,
  812. /* scale */ NO_SCALE,
  813. /* argCount */ 0
  814. },
  815. /* SCALAR_DAYNAME */
  816. {
  817. /* name */ (LPUSTR) "DAYNAME",
  818. /* dataType */ TYPE_CHAR,
  819. /* sqlType */ SQL_VARCHAR,
  820. /* precision */ MAX_CHAR_LITERAL_LENGTH,
  821. /* scale */ 0,
  822. /* argCount */ 1,
  823. /* argType[] */ { TYPE_UNKNOWN }
  824. },
  825. /* SCALAR_DAYOFMONTH_CHAR */
  826. {
  827. /* name */ (LPUSTR) "DAYOFMONTH",
  828. /* dataType */ TYPE_INTEGER,
  829. /* sqlType */ SQL_TINYINT,
  830. /* precision */ 3,
  831. /* scale */ 0,
  832. /* argCount */ 1,
  833. /* argType[] */ { TYPE_CHAR }
  834. },
  835. /* SCALAR_DAYOFMONTH_DATE */
  836. {
  837. /* name */ (LPUSTR) "DAYOFMONTH",
  838. /* dataType */ TYPE_INTEGER,
  839. /* sqlType */ SQL_TINYINT,
  840. /* precision */ 3,
  841. /* scale */ 0,
  842. /* argCount */ 1,
  843. /* argType[] */ { TYPE_DATE }
  844. },
  845. /* SCALAR_DAYOFMONTH_TIMESTAMP */
  846. {
  847. /* name */ (LPUSTR) "DAYOFMONTH",
  848. /* dataType */ TYPE_INTEGER,
  849. /* sqlType */ SQL_TINYINT,
  850. /* precision */ 3,
  851. /* scale */ 0,
  852. /* argCount */ 1,
  853. /* argType[] */ { TYPE_TIMESTAMP }
  854. },
  855. /* SCALAR_DAYOFWEEK */
  856. {
  857. /* name */ (LPUSTR) "DAYOFWEEK",
  858. /* dataType */ TYPE_INTEGER,
  859. /* sqlType */ SQL_TINYINT,
  860. /* precision */ 3,
  861. /* scale */ 0,
  862. /* argCount */ 1,
  863. /* argType[] */ { TYPE_UNKNOWN }
  864. },
  865. /* SCALAR_DAYOFYEAR */
  866. {
  867. /* name */ (LPUSTR) "DAYOFYEAR",
  868. /* dataType */ TYPE_INTEGER,
  869. /* sqlType */ SQL_SMALLINT,
  870. /* precision */ 5,
  871. /* scale */ 0,
  872. /* argCount */ 1,
  873. /* argType[] */ { TYPE_UNKNOWN }
  874. },
  875. /* SCALAR_HOUR_CHAR */
  876. {
  877. /* name */ (LPUSTR) "HOUR",
  878. /* dataType */ TYPE_INTEGER,
  879. /* sqlType */ SQL_TINYINT,
  880. /* precision */ 3,
  881. /* scale */ 0,
  882. /* argCount */ 1,
  883. /* argType[] */ { TYPE_CHAR }
  884. },
  885. /* SCALAR_HOUR_TIME */
  886. {
  887. /* name */ (LPUSTR) "HOUR",
  888. /* dataType */ TYPE_INTEGER,
  889. /* sqlType */ SQL_TINYINT,
  890. /* precision */ 3,
  891. /* scale */ 0,
  892. /* argCount */ 1,
  893. /* argType[] */ { TYPE_TIME }
  894. },
  895. /* SCALAR_HOUR_TIMESTAMP */
  896. {
  897. /* name */ (LPUSTR) "HOUR",
  898. /* dataType */ TYPE_INTEGER,
  899. /* sqlType */ SQL_TINYINT,
  900. /* precision */ 3,
  901. /* scale */ 0,
  902. /* argCount */ 1,
  903. /* argType[] */ { TYPE_TIMESTAMP }
  904. },
  905. /* SCALAR_MINUTE_CHAR */
  906. {
  907. /* name */ (LPUSTR) "MINUTE",
  908. /* dataType */ TYPE_INTEGER,
  909. /* sqlType */ SQL_TINYINT,
  910. /* precision */ 3,
  911. /* scale */ 0,
  912. /* argCount */ 1,
  913. /* argType[] */ { TYPE_CHAR }
  914. },
  915. /* SCALAR_MINUTE_TIME */
  916. {
  917. /* name */ (LPUSTR) "MINUTE",
  918. /* dataType */ TYPE_INTEGER,
  919. /* sqlType */ SQL_TINYINT,
  920. /* precision */ 3,
  921. /* scale */ 0,
  922. /* argCount */ 1,
  923. /* argType[] */ { TYPE_TIME }
  924. },
  925. /* SCALAR_MINUTE_TIMESTAMP */
  926. {
  927. /* name */ (LPUSTR) "MINUTE",
  928. /* dataType */ TYPE_INTEGER,
  929. /* sqlType */ SQL_TINYINT,
  930. /* precision */ 3,
  931. /* scale */ 0,
  932. /* argCount */ 1,
  933. /* argType[] */ { TYPE_TIMESTAMP }
  934. },
  935. /* SCALAR_MONTH_CHAR */
  936. {
  937. /* name */ (LPUSTR) "MONTH",
  938. /* dataType */ TYPE_INTEGER,
  939. /* sqlType */ SQL_TINYINT,
  940. /* precision */ 3,
  941. /* scale */ 0,
  942. /* argCount */ 1,
  943. /* argType[] */ { TYPE_CHAR }
  944. },
  945. /* SCALAR_MONTH_DATE */
  946. {
  947. /* name */ (LPUSTR) "MONTH",
  948. /* dataType */ TYPE_INTEGER,
  949. /* sqlType */ SQL_TINYINT,
  950. /* precision */ 3,
  951. /* scale */ 0,
  952. /* argCount */ 1,
  953. /* argType[] */ { TYPE_DATE }
  954. },
  955. /* SCALAR_MONTH_TIMESTAMP */
  956. {
  957. /* name */ (LPUSTR) "MONTH",
  958. /* dataType */ TYPE_INTEGER,
  959. /* sqlType */ SQL_TINYINT,
  960. /* precision */ 3,
  961. /* scale */ 0,
  962. /* argCount */ 1,
  963. /* argType[] */ { TYPE_TIMESTAMP }
  964. },
  965. /* SCALAR_MONTHNAME_CHAR */
  966. {
  967. /* name */ (LPUSTR) "MONTHNAME",
  968. /* dataType */ TYPE_CHAR,
  969. /* sqlType */ SQL_VARCHAR,
  970. /* precision */ MAX_CHAR_LITERAL_LENGTH,
  971. /* scale */ 0,
  972. /* argCount */ 1,
  973. /* argType[] */ { TYPE_CHAR }
  974. },
  975. /* SCALAR_MONTHNAME_DATE */
  976. {
  977. /* name */ (LPUSTR) "MONTHNAME",
  978. /* dataType */ TYPE_CHAR,
  979. /* sqlType */ SQL_VARCHAR,
  980. /* precision */ MAX_CHAR_LITERAL_LENGTH,
  981. /* scale */ 0,
  982. /* argCount */ 1,
  983. /* argType[] */ { TYPE_DATE }
  984. },
  985. /* SCALAR_MONTHNAME_TIMESTAMP */
  986. {
  987. /* name */ (LPUSTR) "MONTHNAME",
  988. /* dataType */ TYPE_CHAR,
  989. /* sqlType */ SQL_VARCHAR,
  990. /* precision */ MAX_CHAR_LITERAL_LENGTH,
  991. /* scale */ 0,
  992. /* argCount */ 1,
  993. /* argType[] */ { TYPE_TIMESTAMP }
  994. },
  995. /* SCALAR_NOW */
  996. {
  997. /* name */ (LPUSTR) "NOW",
  998. /* dataType */ TYPE_TIMESTAMP,
  999. /* sqlType */ SQL_TIMESTAMP,
  1000. #if TIMESTAMP_SCALE
  1001. /* precision */ 20 + TIMESTAMP_SCALE,
  1002. #else
  1003. /* precision */ 19,
  1004. #endif
  1005. /* scale */ TIMESTAMP_SCALE,
  1006. /* argCount */ 0
  1007. },
  1008. /* SCALAR_QUARTER_CHAR */
  1009. {
  1010. /* name */ (LPUSTR) "QUARTER",
  1011. /* dataType */ TYPE_INTEGER,
  1012. /* sqlType */ SQL_TINYINT,
  1013. /* precision */ 3,
  1014. /* scale */ 0,
  1015. /* argCount */ 1,
  1016. /* argType[] */ { TYPE_CHAR }
  1017. },
  1018. /* SCALAR_QUARTER_DATE */
  1019. {
  1020. /* name */ (LPUSTR) "QUARTER",
  1021. /* dataType */ TYPE_INTEGER,
  1022. /* sqlType */ SQL_TINYINT,
  1023. /* precision */ 3,
  1024. /* scale */ 0,
  1025. /* argCount */ 1,
  1026. /* argType[] */ { TYPE_DATE }
  1027. },
  1028. /* SCALAR_QUARTER_TIMESTAMP */
  1029. {
  1030. /* name */ (LPUSTR) "QUARTER",
  1031. /* dataType */ TYPE_INTEGER,
  1032. /* sqlType */ SQL_TINYINT,
  1033. /* precision */ 3,
  1034. /* scale */ 0,
  1035. /* argCount */ 1,
  1036. /* argType[] */ { TYPE_TIMESTAMP }
  1037. },
  1038. /* SCALAR_SECOND_CHAR */
  1039. {
  1040. /* name */ (LPUSTR) "SECOND",
  1041. /* dataType */ TYPE_INTEGER,
  1042. /* sqlType */ SQL_TINYINT,
  1043. /* precision */ 3,
  1044. /* scale */ 0,
  1045. /* argCount */ 1,
  1046. /* argType[] */ { TYPE_CHAR }
  1047. },
  1048. /* SCALAR_SECOND_TIME */
  1049. {
  1050. /* name */ (LPUSTR) "SECOND",
  1051. /* dataType */ TYPE_INTEGER,
  1052. /* sqlType */ SQL_TINYINT,
  1053. /* precision */ 3,
  1054. /* scale */ 0,
  1055. /* argCount */ 1,
  1056. /* argType[] */ { TYPE_TIME }
  1057. },
  1058. /* SCALAR_SECOND_TIMESTAMP */
  1059. {
  1060. /* name */ (LPUSTR) "SECOND",
  1061. /* dataType */ TYPE_INTEGER,
  1062. /* sqlType */ SQL_TINYINT,
  1063. /* precision */ 3,
  1064. /* scale */ 0,
  1065. /* argCount */ 1,
  1066. /* argType[] */ { TYPE_TIMESTAMP }
  1067. },
  1068. /* SCALAR_TIMESTAMPADD */
  1069. {
  1070. /* name */ (LPUSTR) "TIMESTAMPADD",
  1071. /* dataType */ TYPE_TIMESTAMP,
  1072. /* sqlType */ SQL_TIMESTAMP,
  1073. #if TIMESTAMP_SCALE
  1074. /* precision */ 20 + TIMESTAMP_SCALE,
  1075. #else
  1076. /* precision */ 19,
  1077. #endif
  1078. /* scale */ TIMESTAMP_SCALE,
  1079. /* argCount */ 2,
  1080. /* argType[] */ { TYPE_INTEGER, TYPE_UNKNOWN }
  1081. },
  1082. /* SCALAR_TIMESTAMPDIFF */
  1083. {
  1084. /* name */ (LPUSTR) "TIMESTAMPDIFF",
  1085. /* dataType */ TYPE_INTEGER,
  1086. /* sqlType */ SQL_INTEGER,
  1087. /* precision */ 10,
  1088. /* scale */ 0,
  1089. /* argCount */ 2,
  1090. /* argType[] */ { TYPE_UNKNOWN, TYPE_UNKNOWN }
  1091. },
  1092. /* SCALAR_WEEK */
  1093. {
  1094. /* name */ (LPUSTR) "WEEK",
  1095. /* dataType */ TYPE_INTEGER,
  1096. /* sqlType */ SQL_TINYINT,
  1097. /* precision */ 3,
  1098. /* scale */ 0,
  1099. /* argCount */ 1,
  1100. /* argType[] */ { TYPE_UNKNOWN }
  1101. },
  1102. /* SCALAR_YEAR_CHAR */
  1103. {
  1104. /* name */ (LPUSTR) "YEAR",
  1105. /* dataType */ TYPE_INTEGER,
  1106. /* sqlType */ SQL_INTEGER,
  1107. /* precision */ 10,
  1108. /* scale */ 0,
  1109. /* argCount */ 1,
  1110. /* argType[] */ { TYPE_CHAR }
  1111. },
  1112. /* SCALAR_YEAR_DATE */
  1113. {
  1114. /* name */ (LPUSTR) "YEAR",
  1115. /* dataType */ TYPE_INTEGER,
  1116. /* sqlType */ SQL_INTEGER,
  1117. /* precision */ 10,
  1118. /* scale */ 0,
  1119. /* argCount */ 1,
  1120. /* argType[] */ { TYPE_DATE }
  1121. },
  1122. /* SCALAR_YEAR_TIMESTAMP */
  1123. {
  1124. /* name */ (LPUSTR) "YEAR",
  1125. /* dataType */ TYPE_INTEGER,
  1126. /* sqlType */ SQL_INTEGER,
  1127. /* precision */ 10,
  1128. /* scale */ 0,
  1129. /* argCount */ 1,
  1130. /* argType[] */ { TYPE_TIMESTAMP }
  1131. },
  1132. /* SCALAR_DATABASE */
  1133. {
  1134. /* name */ (LPUSTR) "DATABASE",
  1135. /* dataType */ TYPE_CHAR,
  1136. /* sqlType */ SQL_VARCHAR,
  1137. /* precision */ MAX_DATABASE_NAME_LENGTH,
  1138. /* scale */ 0,
  1139. /* argCount */ 0
  1140. },
  1141. /* SCALAR_IFNULL */
  1142. {
  1143. /* name */ (LPUSTR) "IFNULL",
  1144. /* dataType */ TYPE_CHAR,
  1145. /* sqlType */ SQL_TYPE_NULL,
  1146. /* precision */ 0,
  1147. /* scale */ 0,
  1148. /* argCount */ 2,
  1149. /* argType[] */ { TYPE_UNKNOWN, TYPE_UNKNOWN }
  1150. },
  1151. /* SCALAR_USER */
  1152. {
  1153. /* name */ (LPUSTR) "USER",
  1154. /* dataType */ TYPE_CHAR,
  1155. /* sqlType */ SQL_VARCHAR,
  1156. /* precision */ MAX_USER_NAME_LENGTH,
  1157. /* scale */ 0,
  1158. /* argCount */ 0
  1159. },
  1160. /* SCALAR_CONVERT */
  1161. {
  1162. /* name */ (LPUSTR) "CONVERT",
  1163. /* dataType */ TYPE_UNKNOWN,
  1164. /* sqlType */ SQL_TYPE_NULL,
  1165. /* precision */ 0,
  1166. /* scale */ 0,
  1167. /* argCount */ 1,
  1168. /* argType[] */ { TYPE_UNKNOWN }
  1169. },
  1170. { (LPUSTR) "" }
  1171. };
  1172. #define SQL_TSI_SECOND 1
  1173. #define SQL_TSI_MINUTE 2
  1174. #define SQL_TSI_HOUR 3
  1175. #define SQL_TSI_DAY 4
  1176. #define SQL_TSI_WEEK 5
  1177. #define SQL_TSI_MONTH 6
  1178. #define SQL_TSI_QUARTER 7
  1179. #define SQL_TSI_YEAR 8
  1180. #define SECONDS_PER_MINUTE (60L)
  1181. #define SECONDS_PER_HOUR (60L * 60L)
  1182. #define SECONDS_PER_DAY (60L * 60L * 24L)
  1183. #define SECONDS_PER_WEEK (60L * 60L * 24L * 7L)
  1184. #define MONTHS_PER_YEAR (12)
  1185. #define MIN(a, b) ((a) < (b) ? (a) : (b))
  1186. #define MAX(a, b) ((a) > (b) ? (a) : (b))
  1187. #define PI 3.14159265358979323846264338327950288419716939937510
  1188. #define BIT_LOW_D ( 0.0)
  1189. #define BIT_HIGH_D ( 1.0)
  1190. #define STINY_LOW_D ( -128.0)
  1191. #define STINY_HIGH_D ( 127.0)
  1192. #define UTINY_LOW_D ( 0.0)
  1193. #define UTINY_HIGH_D ( 255.0)
  1194. #define SSHORT_LOW_D ( -32768.0)
  1195. #define SSHORT_HIGH_D ( 32767.0)
  1196. #define USHORT_LOW_D ( 0.0)
  1197. #define USHORT_HIGH_D ( 65535.0)
  1198. #define SLONG_LOW_D (-2147483648.0)
  1199. #define SLONG_HIGH_D ( 2147483647.0)
  1200. #define ULONG_LOW_D ( 0.0)
  1201. #define ULONG_HIGH_D ( 4294967296.0)
  1202. #define FLOAT_LOW_D ( -3.4E38)
  1203. #define FLOAT_HIGH_D ( 3.4E38)
  1204. #define DOUBLE_LOW_D ( -1.7E308)
  1205. #define DOUBLE_HIGH_D ( 1.7E308)
  1206. /***************************************************************************/
  1207. SWORD ScalarIfNullType(LPSQLNODE lpSqlNodeLeft, LPSQLNODE lpSqlNodeRight,
  1208. LPSQLNODE lpSqlNode)
  1209. {
  1210. /* Error if type not compatible? */
  1211. if (!((lpSqlNodeLeft->sqlDataType == lpSqlNodeRight->sqlDataType) ||
  1212. ((lpSqlNodeLeft->sqlDataType == TYPE_DOUBLE) &&
  1213. (lpSqlNodeRight->sqlDataType == TYPE_NUMERIC)) ||
  1214. ((lpSqlNodeLeft->sqlDataType == TYPE_DOUBLE) &&
  1215. (lpSqlNodeRight->sqlDataType == TYPE_INTEGER)) ||
  1216. ((lpSqlNodeLeft->sqlDataType == TYPE_NUMERIC) &&
  1217. (lpSqlNodeRight->sqlDataType == TYPE_DOUBLE)) ||
  1218. ((lpSqlNodeLeft->sqlDataType == TYPE_NUMERIC) &&
  1219. (lpSqlNodeRight->sqlDataType == TYPE_INTEGER)) ||
  1220. ((lpSqlNodeLeft->sqlDataType == TYPE_INTEGER) &&
  1221. (lpSqlNodeRight->sqlDataType == TYPE_DOUBLE)) ||
  1222. ((lpSqlNodeLeft->sqlDataType == TYPE_INTEGER) &&
  1223. (lpSqlNodeRight->sqlDataType == TYPE_NUMERIC))))
  1224. return ERR_SCALARBADARG;
  1225. /* Figure out resultant type */
  1226. if ((lpSqlNodeLeft->sqlDataType == TYPE_NUMERIC) &&
  1227. (lpSqlNodeRight->sqlDataType == TYPE_DOUBLE))
  1228. lpSqlNode->sqlDataType = TYPE_DOUBLE;
  1229. else if ((lpSqlNodeLeft->sqlDataType == TYPE_INTEGER) &&
  1230. (lpSqlNodeRight->sqlDataType == TYPE_DOUBLE))
  1231. lpSqlNode->sqlDataType = TYPE_DOUBLE;
  1232. else if ((lpSqlNodeLeft->sqlDataType == TYPE_INTEGER) &&
  1233. (lpSqlNodeRight->sqlDataType == TYPE_NUMERIC))
  1234. lpSqlNode->sqlDataType = TYPE_NUMERIC;
  1235. else
  1236. lpSqlNode->sqlDataType = lpSqlNodeLeft->sqlDataType;
  1237. /* Figure out resultant SQL type, precision, and scale */
  1238. switch (lpSqlNodeLeft->sqlSqlType) {
  1239. case SQL_DOUBLE:
  1240. lpSqlNode->sqlSqlType = SQL_DOUBLE;
  1241. lpSqlNode->sqlPrecision = 15;
  1242. lpSqlNode->sqlScale = NO_SCALE;
  1243. break;
  1244. case SQL_FLOAT:
  1245. if (lpSqlNodeRight->sqlSqlType == SQL_DOUBLE)
  1246. lpSqlNode->sqlSqlType = SQL_DOUBLE;
  1247. else
  1248. lpSqlNode->sqlSqlType = SQL_FLOAT;
  1249. lpSqlNode->sqlPrecision = 15;
  1250. lpSqlNode->sqlScale = NO_SCALE;
  1251. break;
  1252. case SQL_REAL:
  1253. if (lpSqlNodeRight->sqlSqlType == SQL_DOUBLE) {
  1254. lpSqlNode->sqlSqlType = SQL_DOUBLE;
  1255. lpSqlNode->sqlPrecision = 15;
  1256. }
  1257. else if (lpSqlNodeRight->sqlSqlType == SQL_FLOAT) {
  1258. lpSqlNode->sqlSqlType = SQL_FLOAT;
  1259. lpSqlNode->sqlPrecision = 15;
  1260. }
  1261. else {
  1262. lpSqlNode->sqlSqlType = SQL_REAL;
  1263. lpSqlNode->sqlPrecision = 7;
  1264. }
  1265. lpSqlNode->sqlScale = NO_SCALE;
  1266. break;
  1267. case SQL_DECIMAL:
  1268. case SQL_NUMERIC:
  1269. case SQL_BIGINT:
  1270. case SQL_INTEGER:
  1271. case SQL_SMALLINT:
  1272. case SQL_TINYINT:
  1273. case SQL_BIT:
  1274. switch (lpSqlNodeRight->sqlSqlType) {
  1275. case SQL_DOUBLE:
  1276. case SQL_FLOAT:
  1277. case SQL_REAL:
  1278. lpSqlNode->sqlSqlType = lpSqlNodeRight->sqlSqlType;
  1279. lpSqlNode->sqlPrecision = lpSqlNodeRight->sqlPrecision;
  1280. lpSqlNode->sqlScale = NO_SCALE;
  1281. break;
  1282. case SQL_DECIMAL:
  1283. case SQL_NUMERIC:
  1284. case SQL_BIGINT:
  1285. case SQL_INTEGER:
  1286. case SQL_SMALLINT:
  1287. case SQL_TINYINT:
  1288. case SQL_BIT:
  1289. if ((lpSqlNodeRight->sqlSqlType == SQL_DECIMAL) ||
  1290. (lpSqlNodeLeft->sqlSqlType == SQL_DECIMAL))
  1291. lpSqlNode->sqlSqlType = SQL_DECIMAL;
  1292. else if ((lpSqlNodeRight->sqlSqlType == SQL_NUMERIC) ||
  1293. (lpSqlNodeLeft->sqlSqlType == SQL_NUMERIC))
  1294. lpSqlNode->sqlSqlType = SQL_NUMERIC;
  1295. else if ((lpSqlNodeRight->sqlSqlType == SQL_BIGINT) ||
  1296. (lpSqlNodeLeft->sqlSqlType == SQL_BIGINT))
  1297. lpSqlNode->sqlSqlType = SQL_BIGINT;
  1298. else if ((lpSqlNodeRight->sqlSqlType == SQL_INTEGER) ||
  1299. (lpSqlNodeLeft->sqlSqlType == SQL_INTEGER))
  1300. lpSqlNode->sqlSqlType = SQL_INTEGER;
  1301. else if ((lpSqlNodeRight->sqlSqlType == SQL_SMALLINT) ||
  1302. (lpSqlNodeLeft->sqlSqlType == SQL_SMALLINT))
  1303. lpSqlNode->sqlSqlType = SQL_SMALLINT;
  1304. else if ((lpSqlNodeRight->sqlSqlType == SQL_TINYINT) ||
  1305. (lpSqlNodeLeft->sqlSqlType == SQL_TINYINT))
  1306. lpSqlNode->sqlSqlType = SQL_TINYINT;
  1307. else
  1308. lpSqlNode->sqlSqlType = SQL_BIT;
  1309. lpSqlNode->sqlScale = MAX(lpSqlNodeRight->sqlScale,
  1310. lpSqlNodeLeft->sqlScale);
  1311. lpSqlNode->sqlPrecision = lpSqlNode->sqlScale +
  1312. MAX(lpSqlNodeRight->sqlPrecision - lpSqlNodeRight->sqlScale,
  1313. lpSqlNodeLeft->sqlPrecision - lpSqlNodeLeft->sqlScale);
  1314. break;
  1315. case SQL_LONGVARCHAR:
  1316. case SQL_VARCHAR:
  1317. case SQL_CHAR:
  1318. case SQL_LONGVARBINARY:
  1319. case SQL_VARBINARY:
  1320. case SQL_BINARY:
  1321. case SQL_DATE:
  1322. case SQL_TIME:
  1323. case SQL_TIMESTAMP:
  1324. return ERR_INTERNAL;
  1325. default:
  1326. return ERR_NOTSUPPORTED;
  1327. }
  1328. break;
  1329. case SQL_LONGVARCHAR:
  1330. return ERR_INTERNAL;
  1331. case SQL_VARCHAR:
  1332. case SQL_CHAR:
  1333. if ((lpSqlNodeRight->sqlSqlType == SQL_VARCHAR) ||
  1334. (lpSqlNodeLeft->sqlSqlType == SQL_VARCHAR))
  1335. lpSqlNode->sqlSqlType = SQL_VARCHAR;
  1336. else
  1337. lpSqlNode->sqlSqlType = SQL_CHAR;
  1338. lpSqlNode->sqlPrecision = MAX(lpSqlNodeRight->sqlPrecision,
  1339. lpSqlNodeLeft->sqlPrecision);
  1340. lpSqlNode->sqlScale = NO_SCALE;
  1341. break;
  1342. case SQL_LONGVARBINARY:
  1343. return ERR_INTERNAL;
  1344. case SQL_VARBINARY:
  1345. case SQL_BINARY:
  1346. if ((lpSqlNodeRight->sqlSqlType == SQL_VARBINARY) ||
  1347. (lpSqlNodeLeft->sqlSqlType == SQL_VARBINARY))
  1348. lpSqlNode->sqlSqlType = SQL_VARBINARY;
  1349. else
  1350. lpSqlNode->sqlSqlType = SQL_BINARY;
  1351. lpSqlNode->sqlPrecision = MAX(lpSqlNodeRight->sqlPrecision,
  1352. lpSqlNodeLeft->sqlPrecision);
  1353. lpSqlNode->sqlScale = NO_SCALE;
  1354. break;
  1355. case SQL_DATE:
  1356. case SQL_TIME:
  1357. case SQL_TIMESTAMP:
  1358. lpSqlNode->sqlSqlType = lpSqlNodeLeft->sqlSqlType;
  1359. lpSqlNode->sqlPrecision = lpSqlNodeLeft->sqlPrecision;
  1360. lpSqlNode->sqlScale = lpSqlNodeLeft->sqlScale;
  1361. break;
  1362. default:
  1363. return ERR_NOTSUPPORTED;
  1364. }
  1365. return ERR_SUCCESS;
  1366. }
  1367. /***************************************************************************/
  1368. RETCODE INTFUNC ScalarCheck(LPSTMT lpstmt, LPSQLTREE FAR *lplpSql,
  1369. SQLNODEIDX idxNode, BOOL fIsGroupby, BOOL fCaseSensitive,
  1370. SQLNODEIDX idxNodeTableOuterJoinFromTables,
  1371. SQLNODEIDX idxEnclosingStatement)
  1372. {
  1373. LPSQLNODE lpSqlNode;
  1374. LPUSTR lpszFunction;
  1375. SWORD err;
  1376. UWORD idx;
  1377. SQLNODEIDX idxValues;
  1378. LPSQLNODE lpSqlNodeValues;
  1379. LPSQLNODE lpSqlNodeValue;
  1380. LPSQLNODE lpSqlNodeValue2;
  1381. LPSCALARFUNC lpScalarFunc;
  1382. SQLNODEIDX idxInterval;
  1383. SQLNODEIDX idxType;
  1384. LPUSTR lpstrInterval;
  1385. LPUSTR lpstrType;
  1386. /* Find first entry for the function */
  1387. lpSqlNode = ToNode(*lplpSql, idxNode);
  1388. lpSqlNode->node.scalar.Id = 0;
  1389. lpszFunction = ToString(*lplpSql, lpSqlNode->node.scalar.Function);
  1390. while (TRUE) {
  1391. lpScalarFunc = &(scalarFuncs[lpSqlNode->node.scalar.Id]);
  1392. if (s_lstrlen(lpScalarFunc->name) == 0) {
  1393. s_lstrcpy(lpstmt->szError, lpszFunction);
  1394. return ERR_SCALARNOTFOUND;
  1395. }
  1396. if (!s_lstrcmpi(lpszFunction, lpScalarFunc->name))
  1397. break;
  1398. (lpSqlNode->node.scalar.Id)++;
  1399. }
  1400. /* TIMESTAMPADD or TIMESTAMPDIFF function? */
  1401. if ((lpSqlNode->node.scalar.Id == SCALAR_TIMESTAMPADD) ||
  1402. (lpSqlNode->node.scalar.Id == SCALAR_TIMESTAMPDIFF)) {
  1403. /* Yes. Get the node with the name of the interval */
  1404. idxInterval = lpSqlNode->node.scalar.Arguments;
  1405. if (idxInterval == NO_SQLNODE) {
  1406. s_lstrcpy(lpstmt->szError, lpszFunction);
  1407. return ERR_SCALARBADARG;
  1408. }
  1409. /* Point the node at the rest of the argument list */
  1410. lpSqlNodeValues = ToNode(*lplpSql, idxInterval);
  1411. lpSqlNode->node.scalar.Arguments = lpSqlNodeValues->node.values.Next;
  1412. /* Look at the node specifying the interval */
  1413. lpSqlNodeValue = ToNode(*lplpSql, lpSqlNodeValues->node.values.Value);
  1414. if (lpSqlNodeValue->sqlNodeType != NODE_TYPE_COLUMN) {
  1415. s_lstrcpy(lpstmt->szError, lpszFunction);
  1416. return ERR_SCALARBADARG;
  1417. }
  1418. if (lpSqlNodeValue->node.column.Tablealias != NO_STRING) {
  1419. s_lstrcpy(lpstmt->szError, lpszFunction);
  1420. return ERR_SCALARBADARG;
  1421. }
  1422. lpstrInterval = ToString(*lplpSql, lpSqlNodeValue->node.column.Column);
  1423. if (!s_lstrcmpi(lpstrInterval, "SQL_TSI_FRAC_SECOND"))
  1424. return ERR_NOTSUPPORTED;
  1425. else if (!s_lstrcmpi(lpstrInterval, "SQL_TSI_SECOND"))
  1426. lpSqlNode->node.scalar.Interval = SQL_TSI_SECOND;
  1427. else if (!s_lstrcmpi(lpstrInterval, "SQL_TSI_MINUTE"))
  1428. lpSqlNode->node.scalar.Interval = SQL_TSI_MINUTE;
  1429. else if (!s_lstrcmpi(lpstrInterval, "SQL_TSI_HOUR"))
  1430. lpSqlNode->node.scalar.Interval = SQL_TSI_HOUR;
  1431. else if (!s_lstrcmpi(lpstrInterval, "SQL_TSI_DAY"))
  1432. lpSqlNode->node.scalar.Interval = SQL_TSI_DAY;
  1433. else if (!s_lstrcmpi(lpstrInterval, "SQL_TSI_WEEK"))
  1434. lpSqlNode->node.scalar.Interval = SQL_TSI_WEEK;
  1435. else if (!s_lstrcmpi(lpstrInterval, "SQL_TSI_MONTH"))
  1436. lpSqlNode->node.scalar.Interval = SQL_TSI_MONTH;
  1437. else if (!s_lstrcmpi(lpstrInterval, "SQL_TSI_QUARTER"))
  1438. lpSqlNode->node.scalar.Interval = SQL_TSI_QUARTER;
  1439. else if (!s_lstrcmpi(lpstrInterval, "SQL_TSI_YEAR"))
  1440. lpSqlNode->node.scalar.Interval = SQL_TSI_YEAR;
  1441. else {
  1442. s_lstrcpy(lpstmt->szError, lpszFunction);
  1443. return ERR_SCALARBADARG;
  1444. }
  1445. }
  1446. /* CONVERT function? */
  1447. else if (lpSqlNode->node.scalar.Id == SCALAR_CONVERT) {
  1448. /* Yes. Get the node with the name of the type */
  1449. idxType = lpSqlNode->node.scalar.Arguments;
  1450. if (idxType == NO_SQLNODE) {
  1451. s_lstrcpy(lpstmt->szError, lpszFunction);
  1452. return ERR_SCALARBADARG;
  1453. }
  1454. lpSqlNodeValues = ToNode(*lplpSql, idxType);
  1455. idxType = lpSqlNodeValues->node.values.Next;
  1456. if (idxType == NO_SQLNODE) {
  1457. s_lstrcpy(lpstmt->szError, lpszFunction);
  1458. return ERR_SCALARBADARG;
  1459. }
  1460. /* Take type name off the argument list */
  1461. lpSqlNodeValues->node.values.Next = NO_SQLNODE;
  1462. lpSqlNodeValues = ToNode(*lplpSql, idxType);
  1463. if (lpSqlNodeValues->node.values.Next != NO_SQLNODE) {
  1464. s_lstrcpy(lpstmt->szError, lpszFunction);
  1465. return ERR_SCALARBADARG;
  1466. }
  1467. /* Get the type name */
  1468. lpSqlNodeValue = ToNode(*lplpSql, lpSqlNodeValues->node.values.Value);
  1469. if (lpSqlNodeValue->sqlNodeType != NODE_TYPE_COLUMN) {
  1470. s_lstrcpy(lpstmt->szError, lpszFunction);
  1471. return ERR_SCALARBADARG;
  1472. }
  1473. if (lpSqlNodeValue->node.column.Tablealias != NO_STRING) {
  1474. s_lstrcpy(lpstmt->szError, lpszFunction);
  1475. return ERR_SCALARBADARG;
  1476. }
  1477. lpstrType = ToString(*lplpSql, lpSqlNodeValue->node.column.Column);
  1478. }
  1479. /* Semantic check the arguments */
  1480. err = SemanticCheck(lpstmt, lplpSql, lpSqlNode->node.scalar.Arguments,
  1481. fIsGroupby, fCaseSensitive,
  1482. idxNodeTableOuterJoinFromTables,
  1483. idxEnclosingStatement);
  1484. if (err != ERR_SUCCESS)
  1485. return err;
  1486. /* Look for correct entry for the function */
  1487. while (TRUE) {
  1488. /* See if datatypes of arguments match */
  1489. idxValues = lpSqlNode->node.scalar.Arguments;
  1490. err = ERR_SUCCESS;
  1491. for (idx = 0; idx < lpScalarFunc->argCount; idx++) {
  1492. /* Error if not enough arguments */
  1493. if (idxValues == NO_SQLNODE) {
  1494. err = ERR_SCALARBADARG;
  1495. break;
  1496. }
  1497. /* Error if a parameter */
  1498. lpSqlNodeValues = ToNode(*lplpSql, idxValues);
  1499. lpSqlNodeValue = ToNode(*lplpSql,
  1500. lpSqlNodeValues->node.values.Value);
  1501. if (lpSqlNodeValue->sqlNodeType == NODE_TYPE_PARAMETER)
  1502. return ERR_UNKNOWNTYPE;
  1503. /* Error if NULL specified */
  1504. if (lpSqlNodeValue->sqlNodeType == NODE_TYPE_NULL) {
  1505. s_lstrcpy(lpstmt->szError, lpszFunction);
  1506. return ERR_SCALARBADARG;
  1507. }
  1508. /* Error if long value specified */
  1509. if ((lpSqlNodeValue->sqlSqlType == SQL_LONGVARCHAR) ||
  1510. (lpSqlNodeValue->sqlSqlType == SQL_LONGVARBINARY)) {
  1511. s_lstrcpy(lpstmt->szError, lpszFunction);
  1512. return ERR_SCALARBADARG;
  1513. }
  1514. /* Check the argument type */
  1515. if (lpScalarFunc->argType[idx] != TYPE_UNKNOWN) {
  1516. if (lpSqlNodeValue->sqlDataType !=
  1517. lpScalarFunc->argType[idx]) {
  1518. err = ERR_SCALARBADARG;
  1519. break;
  1520. }
  1521. }
  1522. /* Check the next argument */
  1523. idxValues = lpSqlNodeValues->node.values.Next;
  1524. }
  1525. /* If this entry matches, leave the loop. */
  1526. if ((idxValues == NO_SQLNODE) && (err == ERR_SUCCESS))
  1527. break;
  1528. /* Point at the next function */
  1529. (lpSqlNode->node.scalar.Id)++;
  1530. /* If no more entries match this function name, error */
  1531. lpScalarFunc = &(scalarFuncs[lpSqlNode->node.scalar.Id]);
  1532. if (s_lstrcmpi(lpScalarFunc->name,
  1533. ToString(*lplpSql, lpSqlNode->node.scalar.Function))) {
  1534. s_lstrcpy(lpstmt->szError, lpszFunction);
  1535. return ERR_SCALARBADARG;
  1536. }
  1537. }
  1538. /* Get pointer to first argument */
  1539. if (lpScalarFunc->argCount > 0) {
  1540. lpSqlNodeValues = ToNode(*lplpSql, lpSqlNode->node.scalar.Arguments);
  1541. lpSqlNodeValue = ToNode(*lplpSql, lpSqlNodeValues->node.values.Value);
  1542. }
  1543. else {
  1544. lpSqlNodeValues = NULL;
  1545. lpSqlNodeValue = NULL;
  1546. }
  1547. /* Convert function? */
  1548. if (lpSqlNode->node.scalar.Id != SCALAR_CONVERT) {
  1549. /* No. Set data type, SQL type, precision, scale */
  1550. lpSqlNode->sqlDataType = lpScalarFunc->dataType;
  1551. lpSqlNode->sqlSqlType = lpScalarFunc->sqlType;
  1552. lpSqlNode->sqlPrecision = lpScalarFunc->precision;
  1553. lpSqlNode->sqlScale = lpScalarFunc->scale;
  1554. /* Inherit SQL type, precision, scale as need be */
  1555. if (lpSqlNode->sqlSqlType == SQL_TYPE_NULL)
  1556. lpSqlNode->sqlSqlType = lpSqlNodeValue->sqlSqlType;
  1557. if (lpSqlNode->sqlPrecision == 0) {
  1558. lpSqlNode->sqlPrecision = lpSqlNodeValue->sqlPrecision;
  1559. lpSqlNode->sqlScale = lpSqlNodeValue->sqlScale;
  1560. }
  1561. }
  1562. else {
  1563. /* Yes. Set up resultant type */
  1564. if (!s_lstrcmpi(lpstrType, "SQL_BIGINT")) {
  1565. lpSqlNode->sqlDataType = TYPE_NUMERIC;
  1566. lpSqlNode->sqlSqlType = SQL_BIGINT;
  1567. switch (lpSqlNodeValue->sqlDataType) {
  1568. case TYPE_INTEGER:
  1569. case TYPE_NUMERIC:
  1570. lpSqlNode->sqlPrecision = lpSqlNodeValue->sqlPrecision;
  1571. break;
  1572. case TYPE_DOUBLE:
  1573. lpSqlNode->sqlPrecision = lpSqlNodeValue->sqlPrecision;
  1574. break;
  1575. case TYPE_CHAR:
  1576. lpSqlNode->sqlPrecision = 20;
  1577. break;
  1578. case TYPE_BINARY:
  1579. lpSqlNode->sqlPrecision = lpSqlNodeValue->sqlPrecision;
  1580. break;
  1581. case TYPE_TIME:
  1582. case TYPE_DATE:
  1583. case TYPE_TIMESTAMP:
  1584. return ERR_NOTCONVERTABLE;
  1585. default:
  1586. return ERR_NOTSUPPORTED;
  1587. }
  1588. lpSqlNode->sqlScale = 0;
  1589. }
  1590. else if (!s_lstrcmpi(lpstrType, "SQL_BINARY") ||
  1591. !s_lstrcmpi(lpstrType, "SQL_VARBINARY")) {
  1592. lpSqlNode->sqlDataType = TYPE_BINARY;
  1593. if (!s_lstrcmpi(lpstrType, "SQL_BINARY"))
  1594. lpSqlNode->sqlSqlType = SQL_BINARY;
  1595. else
  1596. lpSqlNode->sqlSqlType = SQL_VARBINARY;
  1597. switch (lpSqlNodeValue->sqlSqlType) {
  1598. case SQL_DECIMAL:
  1599. case SQL_NUMERIC:
  1600. case SQL_BIGINT:
  1601. if (lpSqlNodeValue->sqlScale == 0)
  1602. lpSqlNode->sqlPrecision = lpSqlNodeValue->sqlPrecision+2;
  1603. else
  1604. lpSqlNode->sqlPrecision = lpSqlNodeValue->sqlPrecision+1;
  1605. break;
  1606. case SQL_TINYINT:
  1607. lpSqlNode->sqlPrecision = sizeof(char);
  1608. break;
  1609. case SQL_SMALLINT:
  1610. lpSqlNode->sqlPrecision = sizeof(short);
  1611. break;
  1612. case SQL_INTEGER:
  1613. lpSqlNode->sqlPrecision = sizeof(long);
  1614. break;
  1615. case SQL_BIT:
  1616. lpSqlNode->sqlPrecision = sizeof(unsigned char);
  1617. break;
  1618. case SQL_REAL:
  1619. lpSqlNode->sqlPrecision = sizeof(float);
  1620. break;
  1621. case SQL_FLOAT:
  1622. case SQL_DOUBLE:
  1623. lpSqlNode->sqlPrecision = sizeof(double);
  1624. break;
  1625. case SQL_CHAR:
  1626. case SQL_VARCHAR:
  1627. lpSqlNode->sqlPrecision = lpSqlNodeValue->sqlPrecision;
  1628. break;
  1629. case SQL_LONGVARCHAR:
  1630. return ERR_NOTSUPPORTED;
  1631. case SQL_BINARY:
  1632. case SQL_VARBINARY:
  1633. lpSqlNode->sqlPrecision = lpSqlNodeValue->sqlPrecision;
  1634. break;
  1635. case SQL_LONGVARBINARY:
  1636. return ERR_NOTSUPPORTED;
  1637. case SQL_DATE:
  1638. lpSqlNode->sqlPrecision = sizeof(DATE_STRUCT);
  1639. break;
  1640. case SQL_TIME:
  1641. lpSqlNode->sqlPrecision = sizeof(TIME_STRUCT);
  1642. break;
  1643. case SQL_TIMESTAMP:
  1644. lpSqlNode->sqlPrecision = sizeof(TIMESTAMP_STRUCT);
  1645. break;
  1646. default:
  1647. return ERR_NOTSUPPORTED;
  1648. }
  1649. lpSqlNode->sqlScale = NO_SCALE;
  1650. }
  1651. else if (!s_lstrcmpi(lpstrType, "SQL_BIT")) {
  1652. lpSqlNode->sqlDataType = TYPE_INTEGER;
  1653. lpSqlNode->sqlSqlType = SQL_BIT;
  1654. lpSqlNode->sqlPrecision = 1;
  1655. lpSqlNode->sqlScale = 0;
  1656. }
  1657. else if (!s_lstrcmpi(lpstrType, "SQL_CHAR") ||
  1658. !s_lstrcmpi(lpstrType, "SQL_VARCHAR")) {
  1659. lpSqlNode->sqlDataType = TYPE_CHAR;
  1660. if (!s_lstrcmpi(lpstrType, "SQL_CHAR"))
  1661. lpSqlNode->sqlSqlType = SQL_CHAR;
  1662. else
  1663. lpSqlNode->sqlSqlType = SQL_VARCHAR;
  1664. switch (lpSqlNodeValue->sqlSqlType) {
  1665. case SQL_DECIMAL:
  1666. case SQL_NUMERIC:
  1667. case SQL_BIGINT:
  1668. if (lpSqlNodeValue->sqlScale == 0)
  1669. lpSqlNode->sqlPrecision = lpSqlNodeValue->sqlPrecision+2;
  1670. else
  1671. lpSqlNode->sqlPrecision = lpSqlNodeValue->sqlPrecision+1;
  1672. break;
  1673. case SQL_TINYINT:
  1674. lpSqlNode->sqlPrecision = 4;
  1675. break;
  1676. case SQL_SMALLINT:
  1677. lpSqlNode->sqlPrecision = 6;
  1678. break;
  1679. case SQL_INTEGER:
  1680. lpSqlNode->sqlPrecision = 11;
  1681. break;
  1682. case SQL_BIT:
  1683. lpSqlNode->sqlPrecision = 1;
  1684. break;
  1685. case SQL_REAL:
  1686. lpSqlNode->sqlPrecision = 13;
  1687. break;
  1688. case SQL_FLOAT:
  1689. case SQL_DOUBLE:
  1690. lpSqlNode->sqlPrecision = 22;
  1691. break;
  1692. case SQL_CHAR:
  1693. case SQL_VARCHAR:
  1694. lpSqlNode->sqlPrecision = lpSqlNodeValue->sqlPrecision;
  1695. break;
  1696. case SQL_LONGVARCHAR:
  1697. return ERR_NOTSUPPORTED;
  1698. case SQL_BINARY:
  1699. case SQL_VARBINARY:
  1700. lpSqlNode->sqlPrecision = lpSqlNodeValue->sqlPrecision * 2;
  1701. if (lpSqlNode->sqlPrecision >= MAX_CHAR_LITERAL_LENGTH)
  1702. lpSqlNode->sqlPrecision = MAX_CHAR_LITERAL_LENGTH;
  1703. break;
  1704. case SQL_LONGVARBINARY:
  1705. return ERR_NOTSUPPORTED;
  1706. case SQL_DATE:
  1707. lpSqlNode->sqlPrecision = 10;
  1708. break;
  1709. case SQL_TIME:
  1710. lpSqlNode->sqlPrecision = 8;
  1711. break;
  1712. case SQL_TIMESTAMP:
  1713. if (TIMESTAMP_SCALE > 0)
  1714. lpSqlNode->sqlPrecision = 20 + TIMESTAMP_SCALE;
  1715. else
  1716. lpSqlNode->sqlPrecision = 19;
  1717. break;
  1718. default:
  1719. return ERR_NOTSUPPORTED;
  1720. }
  1721. lpSqlNode->sqlScale = NO_SCALE;
  1722. }
  1723. else if (!s_lstrcmpi(lpstrType, "SQL_DATE")) {
  1724. lpSqlNode->sqlDataType = TYPE_DATE;
  1725. lpSqlNode->sqlSqlType = SQL_DATE;
  1726. lpSqlNode->sqlPrecision = 10;
  1727. lpSqlNode->sqlScale = NO_SCALE;
  1728. }
  1729. else if (!s_lstrcmpi(lpstrType, "SQL_DECIMAL")) {
  1730. lpSqlNode->sqlDataType = TYPE_NUMERIC;
  1731. lpSqlNode->sqlSqlType = SQL_DECIMAL;
  1732. switch (lpSqlNodeValue->sqlDataType) {
  1733. case TYPE_INTEGER:
  1734. case TYPE_NUMERIC:
  1735. lpSqlNode->sqlPrecision = lpSqlNodeValue->sqlPrecision;
  1736. lpSqlNode->sqlScale = lpSqlNodeValue->sqlScale;
  1737. break;
  1738. case TYPE_DOUBLE:
  1739. lpSqlNode->sqlPrecision = lpSqlNodeValue->sqlPrecision;
  1740. lpSqlNode->sqlScale = 3;
  1741. break;
  1742. case TYPE_CHAR:
  1743. lpSqlNode->sqlPrecision = 15;
  1744. lpSqlNode->sqlScale = 3;
  1745. break;
  1746. case TYPE_BINARY:
  1747. lpSqlNode->sqlPrecision = lpSqlNodeValue->sqlPrecision;
  1748. lpSqlNode->sqlScale = 3;
  1749. break;
  1750. case TYPE_TIME:
  1751. case TYPE_DATE:
  1752. case TYPE_TIMESTAMP:
  1753. return ERR_NOTCONVERTABLE;
  1754. default:
  1755. return ERR_NOTSUPPORTED;
  1756. }
  1757. }
  1758. else if (!s_lstrcmpi(lpstrType, "SQL_DOUBLE")) {
  1759. lpSqlNode->sqlDataType = TYPE_DOUBLE;
  1760. lpSqlNode->sqlSqlType = SQL_DOUBLE;
  1761. lpSqlNode->sqlPrecision = 15;
  1762. lpSqlNode->sqlScale = NO_SCALE;
  1763. }
  1764. else if (!s_lstrcmpi(lpstrType, "SQL_FLOAT")) {
  1765. lpSqlNode->sqlDataType = TYPE_DOUBLE;
  1766. lpSqlNode->sqlSqlType = SQL_FLOAT;
  1767. lpSqlNode->sqlPrecision = 15;
  1768. lpSqlNode->sqlScale = NO_SCALE;
  1769. }
  1770. else if (!s_lstrcmpi(lpstrType, "SQL_INTEGER")) {
  1771. lpSqlNode->sqlDataType = TYPE_INTEGER;
  1772. lpSqlNode->sqlSqlType = SQL_INTEGER;
  1773. lpSqlNode->sqlPrecision = 10;
  1774. lpSqlNode->sqlScale = 0;
  1775. }
  1776. else if (!s_lstrcmpi(lpstrType, "SQL_LONGVARBINARY")) {
  1777. return ERR_NOTSUPPORTED;
  1778. }
  1779. else if (!s_lstrcmpi(lpstrType, "SQL_LONGVARCHAR")) {
  1780. return ERR_NOTSUPPORTED;
  1781. }
  1782. else if (!s_lstrcmpi(lpstrType, "SQL_NUMERIC")) {
  1783. lpSqlNode->sqlDataType = TYPE_NUMERIC;
  1784. lpSqlNode->sqlSqlType = SQL_NUMERIC;
  1785. switch (lpSqlNodeValue->sqlDataType) {
  1786. case TYPE_INTEGER:
  1787. case TYPE_NUMERIC:
  1788. lpSqlNode->sqlPrecision = lpSqlNodeValue->sqlPrecision;
  1789. lpSqlNode->sqlScale = lpSqlNodeValue->sqlScale;
  1790. break;
  1791. case TYPE_DOUBLE:
  1792. lpSqlNode->sqlPrecision = lpSqlNodeValue->sqlPrecision;
  1793. lpSqlNode->sqlScale = 3;
  1794. break;
  1795. case TYPE_CHAR:
  1796. lpSqlNode->sqlPrecision = 15;
  1797. lpSqlNode->sqlScale = 3;
  1798. break;
  1799. case TYPE_BINARY:
  1800. lpSqlNode->sqlPrecision = lpSqlNodeValue->sqlPrecision;
  1801. lpSqlNode->sqlScale = 3;
  1802. break;
  1803. case TYPE_TIME:
  1804. case TYPE_DATE:
  1805. case TYPE_TIMESTAMP:
  1806. return ERR_NOTCONVERTABLE;
  1807. default:
  1808. return ERR_NOTSUPPORTED;
  1809. }
  1810. }
  1811. else if (!s_lstrcmpi(lpstrType, "SQL_REAL")) {
  1812. lpSqlNode->sqlDataType = TYPE_DOUBLE;
  1813. lpSqlNode->sqlSqlType = SQL_REAL;
  1814. lpSqlNode->sqlPrecision = 7;
  1815. lpSqlNode->sqlScale = NO_SCALE;
  1816. }
  1817. else if (!s_lstrcmpi(lpstrType, "SQL_SMALLINT")) {
  1818. lpSqlNode->sqlDataType = TYPE_INTEGER;
  1819. lpSqlNode->sqlSqlType = SQL_SMALLINT;
  1820. lpSqlNode->sqlPrecision = 5;
  1821. lpSqlNode->sqlScale = 0;
  1822. }
  1823. else if (!s_lstrcmpi(lpstrType, "SQL_TIME")) {
  1824. lpSqlNode->sqlDataType = TYPE_TIME;
  1825. lpSqlNode->sqlSqlType = SQL_TIME;
  1826. lpSqlNode->sqlPrecision = 6;
  1827. lpSqlNode->sqlScale = NO_SCALE;
  1828. }
  1829. else if (!s_lstrcmpi(lpstrType, "SQL_TIMESTAMP")) {
  1830. lpSqlNode->sqlDataType = TYPE_TIMESTAMP;
  1831. lpSqlNode->sqlSqlType = SQL_TIMESTAMP;
  1832. if (TIMESTAMP_SCALE > 0)
  1833. lpSqlNode->sqlPrecision = 20 + TIMESTAMP_SCALE;
  1834. else
  1835. lpSqlNode->sqlPrecision = 19;
  1836. lpSqlNode->sqlScale = TIMESTAMP_SCALE;
  1837. }
  1838. else if (!s_lstrcmpi(lpstrType, "SQL_TINYINT")) {
  1839. lpSqlNode->sqlDataType = TYPE_INTEGER;
  1840. lpSqlNode->sqlSqlType = SQL_TINYINT;
  1841. lpSqlNode->sqlPrecision = 3;
  1842. lpSqlNode->sqlScale = 0;
  1843. }
  1844. else {
  1845. s_lstrcpy(lpstmt->szError, lpszFunction);
  1846. return ERR_SCALARBADARG;
  1847. }
  1848. }
  1849. /* Adjust the resultant type information as need be */
  1850. switch (lpSqlNode->node.scalar.Id) {
  1851. case SCALAR_ASCII:
  1852. case SCALAR_CHAR:
  1853. break;
  1854. case SCALAR_CONCAT:
  1855. lpSqlNodeValues = ToNode(*lplpSql, lpSqlNodeValues->node.values.Next);
  1856. lpSqlNodeValue = ToNode(*lplpSql, lpSqlNodeValues->node.values.Value);
  1857. lpSqlNode->sqlPrecision += (lpSqlNodeValue->sqlPrecision);
  1858. lpSqlNode->sqlPrecision = MIN(lpSqlNode->sqlPrecision,
  1859. MAX_CHAR_LITERAL_LENGTH);
  1860. break;
  1861. case SCALAR_DIFFERENCE:
  1862. case SCALAR_INSERT:
  1863. case SCALAR_LCASE:
  1864. case SCALAR_LEFT:
  1865. case SCALAR_LENGTH:
  1866. case SCALAR_LOCATE:
  1867. case SCALAR_LOCATE_START:
  1868. case SCALAR_LTRIM:
  1869. case SCALAR_REPEAT:
  1870. case SCALAR_REPLACE:
  1871. case SCALAR_RIGHT:
  1872. case SCALAR_RTRIM:
  1873. case SCALAR_SOUNDEX:
  1874. case SCALAR_SPACE:
  1875. case SCALAR_SUBSTRING:
  1876. case SCALAR_UCASE:
  1877. case SCALAR_ABS_DOUBLE:
  1878. case SCALAR_ABS_NUMERIC:
  1879. case SCALAR_ABS_INTEGER:
  1880. case SCALAR_ACOS:
  1881. case SCALAR_ASIN:
  1882. case SCALAR_ATAN:
  1883. case SCALAR_ATAN2:
  1884. case SCALAR_CEILING_DOUBLE:
  1885. case SCALAR_CEILING_NUMERIC:
  1886. case SCALAR_CEILING_INTEGER:
  1887. case SCALAR_COS:
  1888. case SCALAR_COT:
  1889. case SCALAR_DEGREES_DOUBLE:
  1890. case SCALAR_DEGREES_NUMERIC:
  1891. case SCALAR_DEGREES_INTEGER:
  1892. case SCALAR_EXP:
  1893. case SCALAR_FLOOR_DOUBLE:
  1894. case SCALAR_FLOOR_NUMERIC:
  1895. case SCALAR_FLOOR_INTEGER:
  1896. case SCALAR_LOG:
  1897. case SCALAR_LOG10:
  1898. case SCALAR_MOD:
  1899. case SCALAR_PI:
  1900. case SCALAR_POWER_DOUBLE:
  1901. case SCALAR_POWER_NUMERIC:
  1902. case SCALAR_POWER_INTEGER:
  1903. case SCALAR_RADIANS_DOUBLE:
  1904. case SCALAR_RADIANS_NUMERIC:
  1905. case SCALAR_RADIANS_INTEGER:
  1906. case SCALAR_RAND:
  1907. case SCALAR_RAND_SEED_DOUBLE:
  1908. case SCALAR_RAND_SEED_NUMERIC:
  1909. case SCALAR_RAND_SEED_INTEGER:
  1910. case SCALAR_ROUND_DOUBLE:
  1911. case SCALAR_ROUND_NUMERIC:
  1912. case SCALAR_ROUND_INTEGER:
  1913. case SCALAR_SIGN_DOUBLE:
  1914. case SCALAR_SIGN_NUMERIC:
  1915. case SCALAR_SIGN_INTEGER:
  1916. case SCALAR_SIN:
  1917. case SCALAR_SQRT:
  1918. case SCALAR_TAN:
  1919. case SCALAR_TRUNCATE_DOUBLE:
  1920. case SCALAR_TRUNCATE_NUMERIC:
  1921. case SCALAR_TRUNCATE_INTEGER:
  1922. case SCALAR_CURDATE:
  1923. case SCALAR_CURTIME:
  1924. break;
  1925. case SCALAR_DAYNAME:
  1926. switch (lpSqlNodeValue->sqlDataType) {
  1927. case TYPE_CHAR:
  1928. case TYPE_DATE:
  1929. case TYPE_TIMESTAMP:
  1930. break;
  1931. case TYPE_TIME:
  1932. case TYPE_DOUBLE:
  1933. case TYPE_NUMERIC:
  1934. case TYPE_INTEGER:
  1935. case TYPE_BINARY:
  1936. s_lstrcpy(lpstmt->szError, lpszFunction);
  1937. return ERR_SCALARBADARG;
  1938. default:
  1939. return ERR_NOTSUPPORTED;
  1940. }
  1941. break;
  1942. case SCALAR_DAYOFMONTH_CHAR:
  1943. case SCALAR_DAYOFMONTH_DATE:
  1944. case SCALAR_DAYOFMONTH_TIMESTAMP:
  1945. break;
  1946. case SCALAR_DAYOFWEEK:
  1947. switch (lpSqlNodeValue->sqlDataType) {
  1948. case TYPE_CHAR:
  1949. case TYPE_DATE:
  1950. case TYPE_TIMESTAMP:
  1951. break;
  1952. case TYPE_TIME:
  1953. case TYPE_DOUBLE:
  1954. case TYPE_NUMERIC:
  1955. case TYPE_INTEGER:
  1956. case TYPE_BINARY:
  1957. s_lstrcpy(lpstmt->szError, lpszFunction);
  1958. return ERR_SCALARBADARG;
  1959. default:
  1960. return ERR_NOTSUPPORTED;
  1961. }
  1962. break;
  1963. case SCALAR_DAYOFYEAR:
  1964. switch (lpSqlNodeValue->sqlDataType) {
  1965. case TYPE_CHAR:
  1966. case TYPE_DATE:
  1967. case TYPE_TIMESTAMP:
  1968. break;
  1969. case TYPE_TIME:
  1970. case TYPE_DOUBLE:
  1971. case TYPE_NUMERIC:
  1972. case TYPE_INTEGER:
  1973. case TYPE_BINARY:
  1974. s_lstrcpy(lpstmt->szError, lpszFunction);
  1975. return ERR_SCALARBADARG;
  1976. default:
  1977. return ERR_NOTSUPPORTED;
  1978. }
  1979. break;
  1980. case SCALAR_HOUR_CHAR:
  1981. case SCALAR_HOUR_TIME:
  1982. case SCALAR_HOUR_TIMESTAMP:
  1983. case SCALAR_MINUTE_CHAR:
  1984. case SCALAR_MINUTE_TIME:
  1985. case SCALAR_MINUTE_TIMESTAMP:
  1986. case SCALAR_MONTH_CHAR:
  1987. case SCALAR_MONTH_DATE:
  1988. case SCALAR_MONTH_TIMESTAMP:
  1989. case SCALAR_MONTHNAME_CHAR:
  1990. case SCALAR_MONTHNAME_DATE:
  1991. case SCALAR_MONTHNAME_TIMESTAMP:
  1992. case SCALAR_NOW:
  1993. case SCALAR_QUARTER_CHAR:
  1994. case SCALAR_QUARTER_DATE:
  1995. case SCALAR_QUARTER_TIMESTAMP:
  1996. case SCALAR_SECOND_CHAR:
  1997. case SCALAR_SECOND_TIME:
  1998. case SCALAR_SECOND_TIMESTAMP:
  1999. break;
  2000. case SCALAR_TIMESTAMPADD:
  2001. lpSqlNodeValues = ToNode(*lplpSql, lpSqlNodeValues->node.values.Next);
  2002. lpSqlNodeValue2 = ToNode(*lplpSql, lpSqlNodeValues->node.values.Value);
  2003. switch (lpSqlNodeValue2->sqlDataType) {
  2004. case TYPE_CHAR:
  2005. case TYPE_DATE:
  2006. case TYPE_TIME:
  2007. case TYPE_TIMESTAMP:
  2008. break;
  2009. case TYPE_DOUBLE:
  2010. case TYPE_NUMERIC:
  2011. case TYPE_INTEGER:
  2012. case TYPE_BINARY:
  2013. s_lstrcpy(lpstmt->szError, lpszFunction);
  2014. return ERR_SCALARBADARG;
  2015. default:
  2016. return ERR_NOTSUPPORTED;
  2017. }
  2018. break;
  2019. case SCALAR_TIMESTAMPDIFF:
  2020. switch (lpSqlNodeValue->sqlDataType) {
  2021. case TYPE_CHAR:
  2022. case TYPE_DATE:
  2023. case TYPE_TIME:
  2024. case TYPE_TIMESTAMP:
  2025. break;
  2026. case TYPE_DOUBLE:
  2027. case TYPE_NUMERIC:
  2028. case TYPE_INTEGER:
  2029. case TYPE_BINARY:
  2030. s_lstrcpy(lpstmt->szError, lpszFunction);
  2031. return ERR_SCALARBADARG;
  2032. default:
  2033. return ERR_NOTSUPPORTED;
  2034. }
  2035. lpSqlNodeValues = ToNode(*lplpSql, lpSqlNodeValues->node.values.Next);
  2036. lpSqlNodeValue2 = ToNode(*lplpSql, lpSqlNodeValues->node.values.Value);
  2037. switch (lpSqlNodeValue2->sqlDataType) {
  2038. case TYPE_CHAR:
  2039. case TYPE_DATE:
  2040. case TYPE_TIME:
  2041. case TYPE_TIMESTAMP:
  2042. break;
  2043. case TYPE_DOUBLE:
  2044. case TYPE_NUMERIC:
  2045. case TYPE_INTEGER:
  2046. case TYPE_BINARY:
  2047. s_lstrcpy(lpstmt->szError, lpszFunction);
  2048. return ERR_SCALARBADARG;
  2049. default:
  2050. return ERR_NOTSUPPORTED;
  2051. }
  2052. break;
  2053. case SCALAR_WEEK:
  2054. switch (lpSqlNodeValue->sqlDataType) {
  2055. case TYPE_CHAR:
  2056. case TYPE_DATE:
  2057. case TYPE_TIMESTAMP:
  2058. break;
  2059. case TYPE_TIME:
  2060. case TYPE_DOUBLE:
  2061. case TYPE_NUMERIC:
  2062. case TYPE_INTEGER:
  2063. case TYPE_BINARY:
  2064. s_lstrcpy(lpstmt->szError, lpszFunction);
  2065. return ERR_SCALARBADARG;
  2066. default:
  2067. return ERR_NOTSUPPORTED;
  2068. }
  2069. break;
  2070. case SCALAR_YEAR_CHAR:
  2071. case SCALAR_YEAR_DATE:
  2072. case SCALAR_YEAR_TIMESTAMP:
  2073. case SCALAR_DATABASE:
  2074. break;
  2075. case SCALAR_IFNULL:
  2076. lpSqlNodeValues = ToNode(*lplpSql, lpSqlNodeValues->node.values.Next);
  2077. lpSqlNodeValue2 = ToNode(*lplpSql, lpSqlNodeValues->node.values.Value);
  2078. err = ScalarIfNullType(lpSqlNodeValue, lpSqlNodeValue2, lpSqlNode);
  2079. if (err != ERR_SUCCESS) {
  2080. if (err == ERR_SCALARBADARG)
  2081. s_lstrcpy(lpstmt->szError, lpszFunction);
  2082. return err;
  2083. }
  2084. break;
  2085. case SCALAR_USER:
  2086. break;
  2087. case SCALAR_CONVERT:
  2088. break;
  2089. }
  2090. return ERR_SUCCESS;
  2091. }
  2092. /***************************************************************************/
  2093. SWORD INTFUNC StringLocate(LPUSTR lpstrSearchString, LPUSTR lpstrString,
  2094. SWORD start)
  2095. {
  2096. SWORD lenString;
  2097. SWORD lenSearchString;
  2098. SWORD idx;
  2099. /* Get the length of the strings */
  2100. lenString = (SWORD) s_lstrlen(lpstrString);
  2101. lenSearchString = (SWORD) s_lstrlen(lpstrSearchString);
  2102. /* If the search string is no bigger than the string, and the starting */
  2103. /* location is within the string... */
  2104. if ((lenSearchString <= lenString) && (start <= lenString)) {
  2105. /* Look at each possible starting location until string is found */
  2106. for (start--; start < lenString - lenSearchString + 1; start++) {
  2107. /* See if the strings are equal */
  2108. for (idx = 0; idx < lenSearchString; idx++) {
  2109. if (lpstrString[start+idx] != lpstrSearchString[idx])
  2110. break;
  2111. }
  2112. /* Are they equal? */
  2113. if (idx == lenSearchString) {
  2114. /* Yes. Return it */
  2115. return (start + 1);
  2116. break;
  2117. }
  2118. }
  2119. }
  2120. /* Search string not found */
  2121. return 0;
  2122. }
  2123. /***************************************************************************/
  2124. RETCODE INTFUNC MakeDate(LPSQLNODE lpSqlNode, struct tm *lpTs)
  2125. {
  2126. DATE_STRUCT date;
  2127. RETCODE err;
  2128. switch(lpSqlNode->sqlDataType) {
  2129. case TYPE_CHAR:
  2130. err = CharToDate(lpSqlNode->value.String,
  2131. s_lstrlen(lpSqlNode->value.String), &date);
  2132. if (err != ERR_SUCCESS)
  2133. return err;
  2134. break;
  2135. case TYPE_DOUBLE:
  2136. case TYPE_NUMERIC:
  2137. case TYPE_INTEGER:
  2138. return ERR_INTERNAL;
  2139. case TYPE_DATE:
  2140. date = lpSqlNode->value.Date;
  2141. break;
  2142. case TYPE_TIME:
  2143. return ERR_INTERNAL;
  2144. case TYPE_TIMESTAMP:
  2145. date.month = lpSqlNode->value.Timestamp.month;
  2146. date.day = lpSqlNode->value.Timestamp.day;
  2147. date.year = lpSqlNode->value.Timestamp.year;
  2148. break;
  2149. case TYPE_BINARY:
  2150. return ERR_INTERNAL;
  2151. default:
  2152. return ERR_NOTSUPPORTED;
  2153. }
  2154. lpTs->tm_mon = date.month - 1;
  2155. lpTs->tm_mday = date.day;
  2156. lpTs->tm_year = date.year - 1900;
  2157. lpTs->tm_hour = 0;
  2158. lpTs->tm_min = 0;
  2159. lpTs->tm_sec = 0;
  2160. lpTs->tm_isdst = 0;
  2161. if (mktime(lpTs) == -1)
  2162. return ERR_NOTCONVERTABLE;
  2163. if (lpTs->tm_isdst != 0) {
  2164. lpTs->tm_mon = date.month - 1;
  2165. lpTs->tm_mday = date.day;
  2166. lpTs->tm_year = date.year - 1900;
  2167. lpTs->tm_hour = 0;
  2168. lpTs->tm_min = 0;
  2169. lpTs->tm_sec = 0;
  2170. lpTs->tm_isdst = 1;
  2171. if (mktime(lpTs) == -1)
  2172. return ERR_NOTCONVERTABLE;
  2173. }
  2174. return ERR_SUCCESS;
  2175. }
  2176. /***************************************************************************/
  2177. RETCODE INTFUNC MakeTimestamp(LPSQLNODE lpSqlNode, struct tm *lpTs,
  2178. time_t *lpT)
  2179. {
  2180. TIMESTAMP_STRUCT timestamp;
  2181. RETCODE err;
  2182. switch(lpSqlNode->sqlDataType) {
  2183. case TYPE_CHAR:
  2184. err = CharToTimestamp(lpSqlNode->value.String,
  2185. s_lstrlen(lpSqlNode->value.String), &timestamp);
  2186. if (err != ERR_SUCCESS)
  2187. return err;
  2188. break;
  2189. case TYPE_DOUBLE:
  2190. case TYPE_NUMERIC:
  2191. case TYPE_INTEGER:
  2192. return ERR_INTERNAL;
  2193. case TYPE_DATE:
  2194. timestamp.month = lpSqlNode->value.Date.month;
  2195. timestamp.day = lpSqlNode->value.Date.day;
  2196. timestamp.year = lpSqlNode->value.Date.year;
  2197. timestamp.hour = 0;
  2198. timestamp.minute = 0;
  2199. timestamp.second = 0;
  2200. timestamp.fraction = 0;
  2201. break;
  2202. case TYPE_TIME:
  2203. time(lpT);
  2204. lpTs = localtime(lpT);
  2205. timestamp.month = lpTs->tm_mon + 1;
  2206. timestamp.day = (UWORD) lpTs->tm_mday;
  2207. timestamp.year = lpTs->tm_year + 1900;
  2208. timestamp.hour = lpSqlNode->value.Time.hour;
  2209. timestamp.minute = lpSqlNode->value.Time.minute;
  2210. timestamp.second = lpSqlNode->value.Time.second;
  2211. timestamp.fraction = 0;
  2212. break;
  2213. case TYPE_TIMESTAMP:
  2214. timestamp = lpSqlNode->value.Timestamp;
  2215. break;
  2216. case TYPE_BINARY:
  2217. return ERR_INTERNAL;
  2218. default:
  2219. return ERR_NOTSUPPORTED;
  2220. }
  2221. lpTs->tm_mon = timestamp.month - 1;
  2222. lpTs->tm_mday = timestamp.day;
  2223. lpTs->tm_year = timestamp.year - 1900;
  2224. lpTs->tm_hour = timestamp.hour;
  2225. lpTs->tm_min = timestamp.minute;
  2226. lpTs->tm_sec = timestamp.second;
  2227. lpTs->tm_isdst = 0;
  2228. *lpT = mktime(lpTs);
  2229. if (*lpT == -1)
  2230. return ERR_NOTCONVERTABLE;
  2231. if (lpTs->tm_isdst != 0) {
  2232. lpTs->tm_mon = timestamp.month - 1;
  2233. lpTs->tm_mday = timestamp.day;
  2234. lpTs->tm_year = timestamp.year - 1900;
  2235. lpTs->tm_hour = timestamp.hour;
  2236. lpTs->tm_min = timestamp.minute;
  2237. lpTs->tm_sec = timestamp.second;
  2238. lpTs->tm_isdst = 1;
  2239. *lpT = mktime(lpTs);
  2240. if (*lpT == -1)
  2241. return ERR_NOTCONVERTABLE;
  2242. }
  2243. return ERR_SUCCESS;
  2244. }
  2245. /***************************************************************************/
  2246. #define MAXSOUNDEX 30
  2247. void INTFUNC soundex(LPUSTR in_str, LPUSTR out_str)
  2248. {
  2249. UCHAR sdex[MAXSOUNDEX+1];
  2250. const UCHAR soundex_table[] = "ABCDABCAACCLMMABCRCDABACAC";
  2251. /* ABCDEFGHIJKLMNOPQRSTUVWXYZ */
  2252. UWORD val;
  2253. UWORD inpos;
  2254. UWORD outpos;
  2255. UWORD inlength;
  2256. UCHAR thischar;
  2257. UCHAR lastchar;
  2258. AnsiUpper((LPSTR) in_str);
  2259. inpos = 0;
  2260. outpos = 0;
  2261. lastchar = '0';
  2262. inlength = (UWORD) s_lstrlen(in_str);
  2263. while ((inpos < inlength) && (outpos < MAXSOUNDEX)) {
  2264. thischar = in_str[inpos];
  2265. if ((thischar >= 'A') && (thischar <= 'Z')) {
  2266. val = thischar - 'A';
  2267. if (inpos == 0) {
  2268. sdex[0] = thischar;
  2269. inpos++;
  2270. outpos++;
  2271. lastchar = soundex_table[val];
  2272. continue;
  2273. }
  2274. }
  2275. else
  2276. val = 0;
  2277. thischar = soundex_table[val];
  2278. if (lastchar == thischar) {
  2279. inpos++;
  2280. continue;
  2281. }
  2282. sdex[outpos] = thischar;
  2283. outpos++;
  2284. lastchar = thischar;
  2285. inpos++;
  2286. }
  2287. sdex[outpos] = '\0';
  2288. s_lstrcpy(out_str, sdex);
  2289. }
  2290. /***************************************************************************/
  2291. SDWORD INTFUNC soundexDifference(LPUSTR str1, LPUSTR str2)
  2292. {
  2293. UCHAR sdex1[MAXSOUNDEX+1];
  2294. UCHAR sdex2[MAXSOUNDEX+1];
  2295. soundex(str1, sdex1);
  2296. soundex(str2, sdex2);
  2297. return (SDWORD) ((sdex1[0]-sdex2[0])*10000000 +
  2298. (sdex1[1]-sdex2[1])*100000 +
  2299. (sdex1[2]-sdex2[2])*1000 +
  2300. (sdex1[3]-sdex2[3])*10 +
  2301. s_lstrcmp(sdex1+4,sdex2+4));
  2302. }
  2303. /***************************************************************************/
  2304. RETCODE INTFUNC InternalEvaluateScalar(LPSTMT lpstmt, LPSQLNODE lpSqlNode)
  2305. {
  2306. LPSCALARFUNC lpScalarFunc;
  2307. UWORD idx;
  2308. LPUSTR lpFrom;
  2309. LPUSTR lpTo;
  2310. UCHAR nibble;
  2311. SQLNODEIDX idxValues;
  2312. LPSQLNODE lpSqlNodeValues;
  2313. LPSQLNODE lpSqlNodeValue[MAX_SCALAR_ARGS];
  2314. LPSQLNODE lpSqlNodeReturnValue;
  2315. RETCODE err;
  2316. LPUSTR lpstr1;
  2317. LPUSTR lpstr2;
  2318. LPUSTR lpstr3;
  2319. LPUSTR lpstr4;
  2320. SWORD sw1;
  2321. SWORD sw2;
  2322. SWORD sw3;
  2323. SWORD sw4;
  2324. UCHAR szBuffer[MAX_CHAR_LITERAL_LENGTH+1];
  2325. SWORD location;
  2326. SWORD length;
  2327. double dbl;
  2328. double power;
  2329. char chr;
  2330. unsigned char uchr;
  2331. long lng;
  2332. short shrt;
  2333. float flt;
  2334. BOOL fFractionalPart;
  2335. SQLNODE sqlNode;
  2336. #ifdef WIN32
  2337. struct tm ts;
  2338. struct tm ts2;
  2339. time_t t;
  2340. time_t t2;
  2341. #else
  2342. static struct tm ts;
  2343. static struct tm ts2;
  2344. static time_t t;
  2345. static time_t t2;
  2346. #endif
  2347. struct tm *lpTs;
  2348. DATE_STRUCT sDate;
  2349. TIME_STRUCT sTime;
  2350. long seed1;
  2351. long seed2;
  2352. long seed3;
  2353. /* For each argument... */
  2354. lpScalarFunc = &(scalarFuncs[lpSqlNode->node.scalar.Id]);
  2355. idxValues = lpSqlNode->node.scalar.Arguments;
  2356. for (idx = 0; idx < lpScalarFunc->argCount; idx++) {
  2357. /* Get value of the argument */
  2358. lpSqlNodeValues = ToNode(lpstmt->lpSqlStmt, idxValues);
  2359. lpSqlNodeValue[idx] = ToNode(lpstmt->lpSqlStmt,
  2360. lpSqlNodeValues->node.values.Value);
  2361. err = EvaluateExpression(lpstmt, lpSqlNodeValue[idx]);
  2362. if (err != ERR_SUCCESS)
  2363. return err;
  2364. /* If argument is null, the result is null */
  2365. if (lpSqlNode->node.scalar.Id != SCALAR_IFNULL) {
  2366. if (lpSqlNodeValue[idx]->sqlIsNull) {
  2367. lpSqlNode->sqlIsNull = TRUE;
  2368. switch (lpSqlNode->sqlDataType) {
  2369. case TYPE_DOUBLE:
  2370. lpSqlNode->value.Double = 0.0;
  2371. break;
  2372. case TYPE_NUMERIC:
  2373. s_lstrcpy(lpSqlNode->value.String, "");
  2374. break;
  2375. case TYPE_INTEGER:
  2376. lpSqlNode->value.Double = 0.0;
  2377. break;
  2378. case TYPE_CHAR:
  2379. s_lstrcpy(lpSqlNode->value.String, "");
  2380. break;
  2381. case TYPE_BINARY:
  2382. BINARY_LENGTH(lpSqlNode->value.Binary) = 0;
  2383. break;
  2384. case TYPE_DATE:
  2385. lpSqlNode->value.Date.year = 0;
  2386. lpSqlNode->value.Date.month = 0;
  2387. lpSqlNode->value.Date.day = 0;
  2388. break;
  2389. case TYPE_TIME:
  2390. lpSqlNode->value.Time.hour = 0;
  2391. lpSqlNode->value.Time.minute = 0;
  2392. lpSqlNode->value.Time.second = 0;
  2393. break;
  2394. case TYPE_TIMESTAMP:
  2395. lpSqlNode->value.Timestamp.year = 0;
  2396. lpSqlNode->value.Timestamp.month = 0;
  2397. lpSqlNode->value.Timestamp.day = 0;
  2398. lpSqlNode->value.Timestamp.hour = 0;
  2399. lpSqlNode->value.Timestamp.minute = 0;
  2400. lpSqlNode->value.Timestamp.second = 0;
  2401. lpSqlNode->value.Timestamp.fraction = 0;
  2402. break;
  2403. }
  2404. return ERR_SUCCESS;
  2405. }
  2406. }
  2407. idxValues = lpSqlNodeValues->node.values.Next;
  2408. }
  2409. /* Do the function */
  2410. lpSqlNode->sqlIsNull = FALSE;
  2411. switch (lpSqlNode->node.scalar.Id) {
  2412. case SCALAR_ASCII:
  2413. lpSqlNode->value.Double =
  2414. (double) lpSqlNodeValue[0]->value.String[0];
  2415. break;
  2416. case SCALAR_CHAR:
  2417. lpSqlNode->value.String[0] = (UCHAR) lpSqlNodeValue[0]->value.Double;
  2418. lpSqlNode->value.String[1] = '\0';
  2419. break;
  2420. case SCALAR_CONCAT:
  2421. lpstr1 = lpSqlNodeValue[0]->value.String;
  2422. lpstr2 = lpSqlNodeValue[1]->value.String;
  2423. if ((s_lstrlen(lpstr1) + s_lstrlen(lpstr2)) > lpSqlNode->sqlPrecision)
  2424. return ERR_CONCATOVERFLOW;
  2425. s_lstrcpy(lpSqlNode->value.String, lpstr1);
  2426. s_lstrcat(lpSqlNode->value.String, lpstr2);
  2427. break;
  2428. case SCALAR_DIFFERENCE:
  2429. lpstr1 = lpSqlNodeValue[0]->value.String;
  2430. lpstr2 = lpSqlNodeValue[1]->value.String;
  2431. lpSqlNode->value.Double = soundexDifference(lpstr1, lpstr2);
  2432. break;
  2433. case SCALAR_INSERT:
  2434. lpstr1 = lpSqlNodeValue[0]->value.String;
  2435. sw2 = (SWORD) lpSqlNodeValue[1]->value.Double;
  2436. sw3 = (SWORD) lpSqlNodeValue[2]->value.Double;
  2437. lpstr4 = lpSqlNodeValue[3]->value.String;
  2438. if ((sw2 < 0) || (sw3 < 0)) {
  2439. s_lstrcpy(lpstmt->szError, lpScalarFunc->name);
  2440. return ERR_SCALARBADARG;
  2441. }
  2442. sw1 = (SWORD) s_lstrlen(lpstr1);
  2443. if (sw1 < sw2) {
  2444. s_lstrcpy(lpstmt->szError, lpScalarFunc->name);
  2445. return ERR_SCALARBADARG;
  2446. }
  2447. if (sw3 > (sw1 - sw2 + 1))
  2448. sw3 = sw1 - sw2 + 1;
  2449. sw4 = (SWORD) s_lstrlen(lpstr4);
  2450. if ((sw1 - sw3 + sw4) > MAX_CHAR_LITERAL_LENGTH) {
  2451. s_lstrcpy(lpstmt->szError, lpScalarFunc->name);
  2452. return ERR_SCALARBADARG;
  2453. }
  2454. s_lstrcpy(lpSqlNode->value.String, lpstr1);
  2455. lpSqlNode->value.String[sw2-1] = '\0';
  2456. s_lstrcat(lpSqlNode->value.String, lpstr4);
  2457. s_lstrcat(lpSqlNode->value.String, lpstr1 + sw2 + sw3 - 1);
  2458. break;
  2459. case SCALAR_LCASE:
  2460. s_lstrcpy(lpSqlNode->value.String, lpSqlNodeValue[0]->value.String);
  2461. AnsiLower((LPSTR) lpSqlNode->value.String);
  2462. break;
  2463. case SCALAR_LEFT:
  2464. lpstr1 = lpSqlNodeValue[0]->value.String;
  2465. sw2 = (SWORD) lpSqlNodeValue[1]->value.Double;
  2466. if (sw2 < 0) {
  2467. s_lstrcpy(lpstmt->szError, lpScalarFunc->name);
  2468. return ERR_SCALARBADARG;
  2469. }
  2470. s_lstrcpy(lpSqlNode->value.String, lpstr1);
  2471. if (sw2 < s_lstrlen(lpstr1))
  2472. lpSqlNode->value.String[sw2] = '\0';
  2473. break;
  2474. case SCALAR_LENGTH:
  2475. lpstr1 = lpSqlNodeValue[0]->value.String;
  2476. sw1 = (SWORD) s_lstrlen(lpstr1);
  2477. while ((sw1 > 0) && (lpstr1[sw1 - 1] == ' '))
  2478. sw1--;
  2479. lpSqlNode->value.Double = sw1;
  2480. break;
  2481. case SCALAR_LOCATE:
  2482. lpstr1 = lpSqlNodeValue[0]->value.String;
  2483. lpstr2 = lpSqlNodeValue[1]->value.String;
  2484. sw3 = 1;
  2485. lpSqlNode->value.Double = StringLocate(lpstr1, lpstr2, 1);
  2486. break;
  2487. case SCALAR_LOCATE_START:
  2488. lpstr1 = lpSqlNodeValue[0]->value.String;
  2489. lpstr2 = lpSqlNodeValue[1]->value.String;
  2490. sw3 = (SWORD) lpSqlNodeValue[2]->value.Double;
  2491. if (sw3 <= 0) {
  2492. s_lstrcpy(lpstmt->szError, lpScalarFunc->name);
  2493. return ERR_SCALARBADARG;
  2494. }
  2495. lpSqlNode->value.Double = StringLocate(lpstr1, lpstr2, sw3);
  2496. break;
  2497. case SCALAR_LTRIM:
  2498. lpstr1 = lpSqlNodeValue[0]->value.String;
  2499. sw1 = 0;
  2500. while (lpstr1[sw1] == ' ')
  2501. sw1++;
  2502. s_lstrcpy(lpSqlNode->value.String, lpstr1 + sw1);
  2503. break;
  2504. case SCALAR_REPEAT:
  2505. lpstr1 = lpSqlNodeValue[0]->value.String;
  2506. sw2 = (SWORD) lpSqlNodeValue[1]->value.Double;
  2507. if ((sw2 < 0) || ((sw2 * s_lstrlen(lpstr1)) > MAX_CHAR_LITERAL_LENGTH)) {
  2508. s_lstrcpy(lpstmt->szError, lpScalarFunc->name);
  2509. return ERR_SCALARBADARG;
  2510. }
  2511. s_lstrcpy(lpSqlNode->value.String, "");
  2512. while (sw2 > 0) {
  2513. s_lstrcat(lpSqlNode->value.String, lpstr1);
  2514. sw2--;
  2515. }
  2516. break;
  2517. case SCALAR_REPLACE:
  2518. lpstr1 = lpSqlNodeValue[0]->value.String;
  2519. lpstr2 = lpSqlNodeValue[1]->value.String;
  2520. lpstr3 = lpSqlNodeValue[2]->value.String;
  2521. if (s_lstrlen(lpstr2) == 0) {
  2522. s_lstrcpy(lpstmt->szError, lpScalarFunc->name);
  2523. return ERR_SCALARBADARG;
  2524. }
  2525. s_lstrcpy(lpSqlNode->value.String, lpstr1);
  2526. if (!s_lstrcmp(lpstr2, lpstr3))
  2527. break;
  2528. while (TRUE) {
  2529. location = StringLocate(lpstr2, lpSqlNode->value.String, 1);
  2530. if (location == 0)
  2531. break;
  2532. if ((s_lstrlen(lpSqlNode->value.String) - s_lstrlen(lpstr2) +
  2533. s_lstrlen(lpstr3)) > MAX_CHAR_LITERAL_LENGTH) {
  2534. s_lstrcpy(lpstmt->szError, lpScalarFunc->name);
  2535. return ERR_SCALARBADARG;
  2536. }
  2537. s_lstrcpy(szBuffer, lpSqlNode->value.String);
  2538. lpSqlNode->value.String[location-1] = '\0';
  2539. s_lstrcat(lpSqlNode->value.String, lpstr3);
  2540. s_lstrcat(lpSqlNode->value.String,
  2541. szBuffer + location + s_lstrlen(lpstr2) - 1);
  2542. }
  2543. break;
  2544. case SCALAR_RIGHT:
  2545. lpstr1 = lpSqlNodeValue[0]->value.String;
  2546. sw2 = (SWORD) lpSqlNodeValue[1]->value.Double;
  2547. if (sw2 < 0) {
  2548. s_lstrcpy(lpstmt->szError, lpScalarFunc->name);
  2549. return ERR_SCALARBADARG;
  2550. }
  2551. if (sw2 > s_lstrlen(lpstr1))
  2552. sw2 = (SWORD) s_lstrlen(lpstr1);
  2553. s_lstrcpy(lpSqlNode->value.String, lpstr1 + s_lstrlen(lpstr1) - sw2);
  2554. break;
  2555. case SCALAR_RTRIM:
  2556. lpstr1 = lpSqlNodeValue[0]->value.String;
  2557. s_lstrcpy(lpSqlNode->value.String, lpstr1);
  2558. sw1 = (SWORD) s_lstrlen(lpSqlNode->value.String);
  2559. while ((sw1 > 0) && (lpSqlNode->value.String[sw1-1] == ' ')) {
  2560. sw1--;
  2561. }
  2562. lpSqlNode->value.String[sw1] = '\0';
  2563. break;
  2564. case SCALAR_SOUNDEX:
  2565. lpstr1 = lpSqlNodeValue[0]->value.String;
  2566. soundex(lpstr1, lpSqlNode->value.String);
  2567. break;
  2568. case SCALAR_SPACE:
  2569. sw1 = (SWORD) lpSqlNodeValue[0]->value.Double;
  2570. if ((sw1 < 0) || (sw1 > MAX_CHAR_LITERAL_LENGTH)) {
  2571. s_lstrcpy(lpstmt->szError, lpScalarFunc->name);
  2572. return ERR_SCALARBADARG;
  2573. }
  2574. s_lstrcpy(lpSqlNode->value.String, "");
  2575. while (sw1 > 0) {
  2576. s_lstrcat(lpSqlNode->value.String, " ");
  2577. sw1--;
  2578. }
  2579. break;
  2580. case SCALAR_SUBSTRING:
  2581. lpstr1 = lpSqlNodeValue[0]->value.String;
  2582. sw2 = (SWORD) lpSqlNodeValue[1]->value.Double;
  2583. sw3 = (SWORD) lpSqlNodeValue[2]->value.Double;
  2584. if ((sw2 < 1) || (sw3 < 0)) {
  2585. s_lstrcpy(lpstmt->szError, lpScalarFunc->name);
  2586. return ERR_SCALARBADARG;
  2587. }
  2588. sw1 = (SWORD) s_lstrlen(lpstr1);
  2589. if (sw1 < sw2) {
  2590. s_lstrcpy(lpstmt->szError, lpScalarFunc->name);
  2591. return ERR_SCALARBADARG;
  2592. }
  2593. if (sw3 > (sw1 - sw2 + 1))
  2594. sw3 = sw1 - sw2 + 1;
  2595. s_lstrcpy(lpSqlNode->value.String, lpstr1 + sw2 - 1);
  2596. lpSqlNode->value.String[sw3] = '\0';
  2597. break;
  2598. case SCALAR_UCASE:
  2599. s_lstrcpy(lpSqlNode->value.String, lpSqlNodeValue[0]->value.String);
  2600. AnsiUpper((LPSTR) lpSqlNode->value.String);
  2601. break;
  2602. case SCALAR_ABS_DOUBLE:
  2603. if (lpSqlNodeValue[0]->value.Double >= 0.0)
  2604. lpSqlNode->value.Double = lpSqlNodeValue[0]->value.Double;
  2605. else
  2606. lpSqlNode->value.Double = -(lpSqlNodeValue[0]->value.Double);
  2607. break;
  2608. case SCALAR_ABS_NUMERIC:
  2609. if (*(lpSqlNodeValue[0]->value.String) != '-')
  2610. s_lstrcpy(lpSqlNode->value.String,lpSqlNodeValue[0]->value.String);
  2611. else
  2612. s_lstrcpy(lpSqlNode->value.String,lpSqlNodeValue[0]->value.String+1);
  2613. break;
  2614. case SCALAR_ABS_INTEGER:
  2615. if (lpSqlNodeValue[0]->value.Double >= 0.0)
  2616. lpSqlNode->value.Double = lpSqlNodeValue[0]->value.Double;
  2617. else
  2618. lpSqlNode->value.Double = -(lpSqlNodeValue[0]->value.Double);
  2619. break;
  2620. case SCALAR_ACOS:
  2621. lpSqlNode->value.Double = acos(lpSqlNodeValue[0]->value.Double);
  2622. break;
  2623. case SCALAR_ASIN:
  2624. lpSqlNode->value.Double = asin(lpSqlNodeValue[0]->value.Double);
  2625. break;
  2626. case SCALAR_ATAN:
  2627. lpSqlNode->value.Double = atan(lpSqlNodeValue[0]->value.Double);
  2628. break;
  2629. case SCALAR_ATAN2:
  2630. lpSqlNode->value.Double = atan2(lpSqlNodeValue[0]->value.Double,
  2631. lpSqlNodeValue[1]->value.Double);
  2632. break;
  2633. case SCALAR_CEILING_DOUBLE:
  2634. lpSqlNode->value.Double = ceil(lpSqlNodeValue[0]->value.Double);
  2635. break;
  2636. case SCALAR_CEILING_NUMERIC:
  2637. lpstr1 = lpSqlNodeValue[0]->value.String;
  2638. sw1 = (SWORD) s_lstrlen(lpstr1);
  2639. fFractionalPart = FALSE;
  2640. for (location = 0; location < sw1; location++) {
  2641. if (lpstr1[location] == '.') {
  2642. location++;
  2643. break;
  2644. }
  2645. }
  2646. for (; location < sw1; location++) {
  2647. if (lpstr1[location] != '0') {
  2648. fFractionalPart = TRUE;
  2649. break;
  2650. }
  2651. }
  2652. if (fFractionalPart && (lpSqlNode->value.String[0] != '-')) {
  2653. sqlNode = *lpSqlNode;
  2654. sqlNode.sqlDataType = TYPE_NUMERIC;
  2655. sqlNode.sqlSqlType = SQL_NUMERIC;
  2656. sqlNode.sqlPrecision = 1;
  2657. sqlNode.sqlScale = 0;
  2658. sqlNode.sqlIsNull = FALSE;
  2659. s_lstrcpy(szBuffer, "1");
  2660. sqlNode.value.String = szBuffer;
  2661. BCDAlgebra(lpSqlNode, lpSqlNodeValue[0], OP_PLUS, &sqlNode,
  2662. NULL, NULL, NULL);
  2663. }
  2664. else {
  2665. s_lstrcpy(lpSqlNode->value.String, lpSqlNodeValue[0]->value.String);
  2666. }
  2667. if (fFractionalPart) {
  2668. for (location = 0; location < s_lstrlen(lpSqlNode->value.String);
  2669. location++) {
  2670. if (lpSqlNode->value.String[location] == '.') {
  2671. location++;
  2672. break;
  2673. }
  2674. }
  2675. for (; location < s_lstrlen(lpSqlNode->value.String); location++)
  2676. lpSqlNode->value.String[location] = '0';
  2677. }
  2678. break;
  2679. case SCALAR_CEILING_INTEGER:
  2680. lpSqlNode->value.Double = lpSqlNodeValue[0]->value.Double;
  2681. break;
  2682. case SCALAR_COS:
  2683. lpSqlNode->value.Double = cos(lpSqlNodeValue[0]->value.Double);
  2684. break;
  2685. case SCALAR_COT:
  2686. lpSqlNode->value.Double = tan(lpSqlNodeValue[0]->value.Double);
  2687. if (lpSqlNode->value.Double == 0.0)
  2688. return ERR_ZERODIVIDE;
  2689. lpSqlNode->value.Double = 1.0 / lpSqlNode->value.Double;
  2690. break;
  2691. case SCALAR_DEGREES_DOUBLE:
  2692. lpSqlNode->value.Double = lpSqlNodeValue[0]->value.Double *
  2693. (360.0 / (2.0 * PI));
  2694. break;
  2695. case SCALAR_DEGREES_NUMERIC:
  2696. CharToDouble(lpSqlNodeValue[0]->value.String,
  2697. s_lstrlen(lpSqlNodeValue[0]->value.String), FALSE,
  2698. DOUBLE_LOW_D, DOUBLE_HIGH_D, &dbl);
  2699. lpSqlNode->value.Double = dbl * (360.0 / (2.0 * PI));
  2700. break;
  2701. case SCALAR_DEGREES_INTEGER:
  2702. lpSqlNode->value.Double = lpSqlNodeValue[0]->value.Double *
  2703. (360.0 / (2.0 * PI));
  2704. break;
  2705. case SCALAR_EXP:
  2706. lpSqlNode->value.Double = exp(lpSqlNodeValue[0]->value.Double);
  2707. break;
  2708. case SCALAR_FLOOR_DOUBLE:
  2709. lpSqlNode->value.Double = floor(lpSqlNodeValue[0]->value.Double);
  2710. break;
  2711. case SCALAR_FLOOR_NUMERIC:
  2712. lpstr1 = lpSqlNodeValue[0]->value.String;
  2713. sw1 = (SWORD) s_lstrlen(lpstr1);
  2714. fFractionalPart = FALSE;
  2715. for (location = 0; location < sw1; location++) {
  2716. if (lpstr1[location] == '.') {
  2717. location++;
  2718. break;
  2719. }
  2720. }
  2721. for (; location < sw1; location++) {
  2722. if (lpstr1[location] != '0') {
  2723. fFractionalPart = TRUE;
  2724. break;
  2725. }
  2726. }
  2727. if (fFractionalPart && (lpSqlNode->value.String[0] == '-')) {
  2728. sqlNode = *lpSqlNode;
  2729. sqlNode.sqlDataType = TYPE_NUMERIC;
  2730. sqlNode.sqlSqlType = SQL_NUMERIC;
  2731. sqlNode.sqlPrecision = 1;
  2732. sqlNode.sqlScale = 0;
  2733. sqlNode.sqlIsNull = FALSE;
  2734. s_lstrcpy(szBuffer, "1");
  2735. sqlNode.value.String = szBuffer;
  2736. BCDAlgebra(lpSqlNode, lpSqlNodeValue[0], OP_MINUS, &sqlNode,
  2737. NULL, NULL, NULL);
  2738. }
  2739. else {
  2740. s_lstrcpy(lpSqlNode->value.String, lpSqlNodeValue[0]->value.String);
  2741. }
  2742. if (fFractionalPart) {
  2743. for (location = 0; location < s_lstrlen(lpSqlNode->value.String);
  2744. location++) {
  2745. if (lpSqlNode->value.String[location] == '.') {
  2746. location++;
  2747. break;
  2748. }
  2749. }
  2750. for (; location < s_lstrlen(lpSqlNode->value.String); location++)
  2751. lpSqlNode->value.String[location] = '0';
  2752. }
  2753. break;
  2754. case SCALAR_FLOOR_INTEGER:
  2755. lpSqlNode->value.Double = lpSqlNodeValue[0]->value.Double;
  2756. break;
  2757. case SCALAR_LOG:
  2758. lpSqlNode->value.Double = log(lpSqlNodeValue[0]->value.Double);
  2759. break;
  2760. case SCALAR_LOG10:
  2761. lpSqlNode->value.Double = log10(lpSqlNodeValue[0]->value.Double);
  2762. break;
  2763. case SCALAR_MOD:
  2764. if (lpSqlNodeValue[1]->value.Double == 0.0)
  2765. return ERR_ZERODIVIDE;
  2766. lpSqlNode->value.Double = ((SDWORD) lpSqlNodeValue[0]->value.Double)
  2767. % ((SDWORD) lpSqlNodeValue[1]->value.Double);
  2768. break;
  2769. case SCALAR_PI:
  2770. lpSqlNode->value.Double = PI;
  2771. break;
  2772. case SCALAR_POWER_DOUBLE:
  2773. lpSqlNode->value.Double = pow(lpSqlNodeValue[0]->value.Double,
  2774. (long) lpSqlNodeValue[1]->value.Double);
  2775. break;
  2776. case SCALAR_POWER_NUMERIC:
  2777. CharToDouble(lpSqlNodeValue[0]->value.String,
  2778. s_lstrlen(lpSqlNodeValue[0]->value.String), FALSE,
  2779. DOUBLE_LOW_D, DOUBLE_HIGH_D, &dbl);
  2780. lpSqlNode->value.Double = pow(dbl,
  2781. (long) lpSqlNodeValue[1]->value.Double);
  2782. break;
  2783. case SCALAR_POWER_INTEGER:
  2784. lpSqlNode->value.Double = pow(lpSqlNodeValue[0]->value.Double,
  2785. (long) lpSqlNodeValue[1]->value.Double);
  2786. break;
  2787. case SCALAR_RADIANS_DOUBLE:
  2788. lpSqlNode->value.Double = lpSqlNodeValue[0]->value.Double *
  2789. ((2.0 * PI) / 360.0);
  2790. break;
  2791. case SCALAR_RADIANS_NUMERIC:
  2792. CharToDouble(lpSqlNodeValue[0]->value.String,
  2793. s_lstrlen(lpSqlNodeValue[0]->value.String), FALSE,
  2794. DOUBLE_LOW_D, DOUBLE_HIGH_D, &dbl);
  2795. lpSqlNode->value.Double = dbl * ((2.0 * PI) / 360.0);
  2796. break;
  2797. case SCALAR_RADIANS_INTEGER:
  2798. lpSqlNode->value.Double = lpSqlNodeValue[0]->value.Double *
  2799. ((2.0 * PI) / 360.0);
  2800. break;
  2801. case SCALAR_RAND:
  2802. case SCALAR_RAND_SEED_DOUBLE:
  2803. case SCALAR_RAND_SEED_NUMERIC:
  2804. case SCALAR_RAND_SEED_INTEGER:
  2805. /* Get seed */
  2806. switch (lpSqlNode->node.scalar.Id) {
  2807. case SCALAR_RAND:
  2808. break;
  2809. case SCALAR_RAND_SEED_DOUBLE:
  2810. if ((long) lpSqlNodeValue[0]->value.Double != 0)
  2811. new_seed = (long) lpSqlNodeValue[0]->value.Double;
  2812. break;
  2813. case SCALAR_RAND_SEED_NUMERIC:
  2814. CharToDouble(lpSqlNodeValue[0]->value.String,
  2815. s_lstrlen(lpSqlNodeValue[0]->value.String), FALSE,
  2816. DOUBLE_LOW_D, DOUBLE_HIGH_D, &dbl);
  2817. if ((long) dbl != 0)
  2818. new_seed = (long) dbl;
  2819. break;
  2820. case SCALAR_RAND_SEED_INTEGER:
  2821. if ((long) lpSqlNodeValue[0]->value.Double != 0)
  2822. new_seed = (long) lpSqlNodeValue[0]->value.Double;
  2823. break;
  2824. }
  2825. /* Make a seed if need be */
  2826. if (new_seed == 0)
  2827. new_seed = time(NULL);
  2828. /* First generator */
  2829. seed1 = new_seed + 4;
  2830. if (seed1 < 0)
  2831. seed1 = -seed1;
  2832. seed1 = (seed1 % 30000) + 1;
  2833. seed1 = (171 * (seed1 % 177)) - (2 * (seed1 / 177));
  2834. if (seed1 < 0)
  2835. seed1 += (30269);
  2836. /* Second generator */
  2837. seed2 = new_seed + 10014;
  2838. if (seed2 < 0)
  2839. seed2 = -seed2;
  2840. seed2 = (seed2 % 30000) + 1;
  2841. seed2 = (172 * (seed2 % 176))- (2 * (seed2 / 176));
  2842. if (seed2 < 0)
  2843. seed2 += (30307);
  2844. /* Third generator */
  2845. seed3 = new_seed + 3017;
  2846. if (seed3 < 0)
  2847. seed3 = -seed3;
  2848. seed3 = (seed3 % 30000) + 1;
  2849. seed3 = (170 * (seed3 % 178)) - (2 * (seed3 / 178));
  2850. if (seed3 < 0)
  2851. seed3 += (30323);
  2852. /* Compute value */
  2853. dbl = (seed1 / 30269.0) + (seed2 / 30307.0) + (seed3 / 30323.0);
  2854. dbl -= ((double) floor(dbl));
  2855. new_seed = (long) (floor(dbl * ULONG_HIGH_D));
  2856. if (new_seed == 0)
  2857. new_seed = seed1 + seed2 + seed3;
  2858. lpSqlNode->value.Double = dbl;
  2859. break;
  2860. case SCALAR_ROUND_DOUBLE:
  2861. power = pow(10, lpSqlNodeValue[1]->value.Double);
  2862. lpSqlNode->value.Double =
  2863. floor((lpSqlNodeValue[0]->value.Double * power) + 0.5) / power;
  2864. break;
  2865. case SCALAR_ROUND_NUMERIC:
  2866. power = pow(10, lpSqlNodeValue[1]->value.Double);
  2867. CharToDouble(lpSqlNodeValue[0]->value.String,
  2868. s_lstrlen(lpSqlNodeValue[0]->value.String), FALSE,
  2869. DOUBLE_LOW_D, DOUBLE_HIGH_D, &dbl);
  2870. dbl = floor((dbl * power) + 0.5) / power;
  2871. if (DoubleToChar(dbl, FALSE, lpSqlNode->value.String,
  2872. 1 + 2 + lpSqlNode->sqlPrecision))
  2873. lpSqlNode->value.String[2 + lpSqlNode->sqlPrecision] = '\0';
  2874. BCDNormalize(lpSqlNode->value.String,
  2875. s_lstrlen(lpSqlNode->value.String),
  2876. lpSqlNode->value.String,
  2877. 1 + 2 + lpSqlNode->sqlPrecision,
  2878. lpSqlNode->sqlPrecision,
  2879. lpSqlNode->sqlScale);
  2880. break;
  2881. case SCALAR_ROUND_INTEGER:
  2882. power = pow(10, lpSqlNodeValue[1]->value.Double);
  2883. lpSqlNode->value.Double =
  2884. floor((lpSqlNodeValue[0]->value.Double * power) + 0.5) / power;
  2885. break;
  2886. case SCALAR_SIGN_DOUBLE:
  2887. if (lpSqlNodeValue[0]->value.Double > 0)
  2888. lpSqlNode->value.Double = 1;
  2889. else if (lpSqlNodeValue[0]->value.Double == 0)
  2890. lpSqlNode->value.Double = 0;
  2891. else
  2892. lpSqlNode->value.Double = -1;
  2893. break;
  2894. case SCALAR_SIGN_NUMERIC:
  2895. switch (lpSqlNodeValue[0]->value.String[0]) {
  2896. case '\0':
  2897. lpSqlNode->value.Double = 0;
  2898. break;
  2899. case '-':
  2900. lpSqlNode->value.Double = -1;
  2901. break;
  2902. default:
  2903. lpSqlNode->value.Double = 1;
  2904. break;
  2905. }
  2906. break;
  2907. case SCALAR_SIGN_INTEGER:
  2908. if (lpSqlNodeValue[0]->value.Double > 0)
  2909. lpSqlNode->value.Double = 1;
  2910. else if (lpSqlNodeValue[0]->value.Double == 0)
  2911. lpSqlNode->value.Double = 0;
  2912. else
  2913. lpSqlNode->value.Double = -1;
  2914. break;
  2915. case SCALAR_SIN:
  2916. lpSqlNode->value.Double = sin(lpSqlNodeValue[0]->value.Double);
  2917. break;
  2918. case SCALAR_SQRT:
  2919. lpSqlNode->value.Double = sqrt(lpSqlNodeValue[0]->value.Double);
  2920. break;
  2921. case SCALAR_TAN:
  2922. lpSqlNode->value.Double = tan(lpSqlNodeValue[0]->value.Double);
  2923. break;
  2924. case SCALAR_TRUNCATE_DOUBLE:
  2925. power = pow(10, lpSqlNodeValue[1]->value.Double);
  2926. lpSqlNode->value.Double =
  2927. floor(lpSqlNodeValue[0]->value.Double * power) / power;
  2928. break;
  2929. case SCALAR_TRUNCATE_NUMERIC:
  2930. power = pow(10, lpSqlNodeValue[1]->value.Double);
  2931. CharToDouble(lpSqlNodeValue[0]->value.String,
  2932. s_lstrlen(lpSqlNodeValue[0]->value.String), FALSE,
  2933. DOUBLE_LOW_D, DOUBLE_HIGH_D, &dbl);
  2934. dbl = floor(dbl * power) / power;
  2935. if (DoubleToChar(dbl, FALSE, lpSqlNode->value.String,
  2936. 1 + 2 + lpSqlNode->sqlPrecision))
  2937. lpSqlNode->value.String[2 + lpSqlNode->sqlPrecision] = '\0';
  2938. BCDNormalize(lpSqlNode->value.String,
  2939. s_lstrlen(lpSqlNode->value.String),
  2940. lpSqlNode->value.String,
  2941. 1 + 2 + lpSqlNode->sqlPrecision,
  2942. lpSqlNode->sqlPrecision,
  2943. lpSqlNode->sqlScale);
  2944. break;
  2945. case SCALAR_TRUNCATE_INTEGER:
  2946. power = pow(10, lpSqlNodeValue[1]->value.Double);
  2947. lpSqlNode->value.Double =
  2948. floor(lpSqlNodeValue[0]->value.Double * power) / power;
  2949. break;
  2950. case SCALAR_CURDATE:
  2951. time(&t);
  2952. lpTs = localtime(&t);
  2953. lpSqlNode->value.Date.month = lpTs->tm_mon + 1;
  2954. lpSqlNode->value.Date.day = (UWORD) lpTs->tm_mday;
  2955. lpSqlNode->value.Date.year = lpTs->tm_year + 1900;
  2956. break;
  2957. case SCALAR_CURTIME:
  2958. time(&t);
  2959. lpTs = localtime(&t);
  2960. lpSqlNode->value.Time.hour = (UWORD) lpTs->tm_hour;
  2961. lpSqlNode->value.Time.minute = (UWORD) lpTs->tm_min;
  2962. lpSqlNode->value.Time.second = (UWORD) lpTs->tm_sec;
  2963. break;
  2964. case SCALAR_DAYNAME:
  2965. err = MakeDate(lpSqlNodeValue[0], &ts);
  2966. if (err != ERR_SUCCESS)
  2967. return err;
  2968. switch (ts.tm_wday) {
  2969. case 0:
  2970. LoadString(s_hModule, STR_SUNDAY, (LPSTR) lpSqlNode->value.String,
  2971. MAX_CHAR_LITERAL_LENGTH+1);
  2972. break;
  2973. case 1:
  2974. LoadString(s_hModule, STR_MONDAY, (LPSTR) lpSqlNode->value.String,
  2975. MAX_CHAR_LITERAL_LENGTH+1);
  2976. break;
  2977. case 2:
  2978. LoadString(s_hModule, STR_TUESDAY, (LPSTR) lpSqlNode->value.String,
  2979. MAX_CHAR_LITERAL_LENGTH+1);
  2980. break;
  2981. case 3:
  2982. LoadString(s_hModule, STR_WEDNESDAY, (LPSTR) lpSqlNode->value.String,
  2983. MAX_CHAR_LITERAL_LENGTH+1);
  2984. break;
  2985. case 4:
  2986. LoadString(s_hModule, STR_THURSDAY, (LPSTR) lpSqlNode->value.String,
  2987. MAX_CHAR_LITERAL_LENGTH+1);
  2988. break;
  2989. case 5:
  2990. LoadString(s_hModule, STR_FRIDAY, (LPSTR) lpSqlNode->value.String,
  2991. MAX_CHAR_LITERAL_LENGTH+1);
  2992. break;
  2993. case 6:
  2994. LoadString(s_hModule, STR_SATURDAY, (LPSTR) lpSqlNode->value.String,
  2995. MAX_CHAR_LITERAL_LENGTH+1);
  2996. break;
  2997. }
  2998. break;
  2999. case SCALAR_DAYOFMONTH_CHAR:
  3000. lpstr1 = lpSqlNodeValue[0]->value.String;
  3001. err = CharToDate(lpstr1, s_lstrlen(lpstr1), &sDate);
  3002. if (err != ERR_SUCCESS)
  3003. return err;
  3004. lpSqlNode->value.Double = sDate.day;
  3005. break;
  3006. case SCALAR_DAYOFMONTH_DATE:
  3007. lpSqlNode->value.Double = lpSqlNodeValue[0]->value.Date.day;
  3008. break;
  3009. case SCALAR_DAYOFMONTH_TIMESTAMP:
  3010. lpSqlNode->value.Double = lpSqlNodeValue[0]->value.Timestamp.day;
  3011. break;
  3012. case SCALAR_DAYOFWEEK:
  3013. err = MakeDate(lpSqlNodeValue[0], &ts);
  3014. if (err != ERR_SUCCESS)
  3015. return err;
  3016. lpSqlNode->value.Double = ts.tm_wday + 1;
  3017. break;
  3018. case SCALAR_DAYOFYEAR:
  3019. err = MakeDate(lpSqlNodeValue[0], &ts);
  3020. if (err != ERR_SUCCESS)
  3021. return err;
  3022. lpSqlNode->value.Double = ts.tm_yday + 1;
  3023. break;
  3024. case SCALAR_HOUR_CHAR:
  3025. lpstr1 = lpSqlNodeValue[0]->value.String;
  3026. err = CharToTime(lpstr1, s_lstrlen(lpstr1), &sTime);
  3027. if (err != ERR_SUCCESS)
  3028. return err;
  3029. lpSqlNode->value.Double = sTime.hour;
  3030. break;
  3031. case SCALAR_HOUR_TIME:
  3032. lpSqlNode->value.Double = lpSqlNodeValue[0]->value.Time.hour;
  3033. break;
  3034. case SCALAR_HOUR_TIMESTAMP:
  3035. lpSqlNode->value.Double = lpSqlNodeValue[0]->value.Timestamp.hour;
  3036. break;
  3037. case SCALAR_MINUTE_CHAR:
  3038. lpstr1 = lpSqlNodeValue[0]->value.String;
  3039. err = CharToTime(lpstr1, s_lstrlen(lpstr1), &sTime);
  3040. if (err != ERR_SUCCESS)
  3041. return err;
  3042. lpSqlNode->value.Double = sTime.minute;
  3043. break;
  3044. case SCALAR_MINUTE_TIME:
  3045. lpSqlNode->value.Double = lpSqlNodeValue[0]->value.Time.minute;
  3046. break;
  3047. case SCALAR_MINUTE_TIMESTAMP:
  3048. lpSqlNode->value.Double = lpSqlNodeValue[0]->value.Timestamp.minute;
  3049. break;
  3050. case SCALAR_MONTH_CHAR:
  3051. lpstr1 = lpSqlNodeValue[0]->value.String;
  3052. err = CharToDate(lpstr1, s_lstrlen(lpstr1), &sDate);
  3053. if (err != ERR_SUCCESS)
  3054. return err;
  3055. lpSqlNode->value.Double = sDate.month;
  3056. break;
  3057. case SCALAR_MONTH_DATE:
  3058. lpSqlNode->value.Double = lpSqlNodeValue[0]->value.Date.month;
  3059. break;
  3060. case SCALAR_MONTH_TIMESTAMP:
  3061. lpSqlNode->value.Double = lpSqlNodeValue[0]->value.Timestamp.month;
  3062. break;
  3063. case SCALAR_MONTHNAME_CHAR:
  3064. case SCALAR_MONTHNAME_DATE:
  3065. case SCALAR_MONTHNAME_TIMESTAMP:
  3066. switch (lpSqlNode->node.scalar.Id) {
  3067. case SCALAR_MONTHNAME_CHAR:
  3068. lpstr1 = lpSqlNodeValue[0]->value.String;
  3069. err = CharToDate(lpstr1, s_lstrlen(lpstr1), &sDate);
  3070. if (err != ERR_SUCCESS)
  3071. return err;
  3072. break;
  3073. case SCALAR_MONTHNAME_DATE:
  3074. sDate = lpSqlNodeValue[0]->value.Date;
  3075. break;
  3076. case SCALAR_MONTHNAME_TIMESTAMP:
  3077. sDate.month = lpSqlNodeValue[0]->value.Timestamp.month;
  3078. sDate.day = lpSqlNodeValue[0]->value.Timestamp.day;
  3079. sDate.year = lpSqlNodeValue[0]->value.Timestamp.year;
  3080. break;
  3081. }
  3082. switch (sDate.month) {
  3083. case 1:
  3084. LoadString(s_hModule, STR_JANUARY, (LPSTR) lpSqlNode->value.String,
  3085. MAX_CHAR_LITERAL_LENGTH+1);
  3086. break;
  3087. case 2:
  3088. LoadString(s_hModule, STR_FEBRUARY, (LPSTR) lpSqlNode->value.String,
  3089. MAX_CHAR_LITERAL_LENGTH+1);
  3090. break;
  3091. case 3:
  3092. LoadString(s_hModule, STR_MARCH, (LPSTR) lpSqlNode->value.String,
  3093. MAX_CHAR_LITERAL_LENGTH+1);
  3094. break;
  3095. case 4:
  3096. LoadString(s_hModule, STR_APRIL, (LPSTR) lpSqlNode->value.String,
  3097. MAX_CHAR_LITERAL_LENGTH+1);
  3098. break;
  3099. case 5:
  3100. LoadString(s_hModule, STR_MAY, (LPSTR) lpSqlNode->value.String,
  3101. MAX_CHAR_LITERAL_LENGTH+1);
  3102. break;
  3103. case 6:
  3104. LoadString(s_hModule, STR_JUNE, (LPSTR) lpSqlNode->value.String,
  3105. MAX_CHAR_LITERAL_LENGTH+1);
  3106. break;
  3107. case 7:
  3108. LoadString(s_hModule, STR_JULY, (LPSTR) lpSqlNode->value.String,
  3109. MAX_CHAR_LITERAL_LENGTH+1);
  3110. break;
  3111. case 8:
  3112. LoadString(s_hModule, STR_AUGUST, (LPSTR) lpSqlNode->value.String,
  3113. MAX_CHAR_LITERAL_LENGTH+1);
  3114. break;
  3115. case 9:
  3116. LoadString(s_hModule, STR_SEPTEMBER, (LPSTR) lpSqlNode->value.String,
  3117. MAX_CHAR_LITERAL_LENGTH+1);
  3118. break;
  3119. case 10:
  3120. LoadString(s_hModule, STR_OCTOBER, (LPSTR) lpSqlNode->value.String,
  3121. MAX_CHAR_LITERAL_LENGTH+1);
  3122. break;
  3123. case 11:
  3124. LoadString(s_hModule, STR_NOVEMBER, (LPSTR) lpSqlNode->value.String,
  3125. MAX_CHAR_LITERAL_LENGTH+1);
  3126. break;
  3127. case 12:
  3128. LoadString(s_hModule, STR_DECEMBER, (LPSTR) lpSqlNode->value.String,
  3129. MAX_CHAR_LITERAL_LENGTH+1);
  3130. break;
  3131. }
  3132. break;
  3133. case SCALAR_NOW:
  3134. time(&t);
  3135. lpTs = localtime(&t);
  3136. lpSqlNode->value.Timestamp.month = lpTs->tm_mon + 1;
  3137. lpSqlNode->value.Timestamp.day = (UWORD) lpTs->tm_mday;
  3138. lpSqlNode->value.Timestamp.year = lpTs->tm_year + 1900;
  3139. lpSqlNode->value.Timestamp.hour = (UWORD) lpTs->tm_hour;
  3140. lpSqlNode->value.Timestamp.minute = (UWORD) lpTs->tm_min;
  3141. lpSqlNode->value.Timestamp.second = (UWORD) lpTs->tm_sec;
  3142. lpSqlNode->value.Timestamp.fraction = 0;
  3143. break;
  3144. case SCALAR_QUARTER_CHAR:
  3145. lpstr1 = lpSqlNodeValue[0]->value.String;
  3146. err = CharToDate(lpstr1, s_lstrlen(lpstr1), &sDate);
  3147. if (err != ERR_SUCCESS)
  3148. return err;
  3149. lpSqlNode->value.Double = ((sDate.month - 1) / 3) + 1;
  3150. break;
  3151. case SCALAR_QUARTER_DATE:
  3152. lpSqlNode->value.Double =
  3153. ((lpSqlNodeValue[0]->value.Date.month - 1) / 3) + 1;
  3154. break;
  3155. case SCALAR_QUARTER_TIMESTAMP:
  3156. lpSqlNode->value.Double =
  3157. ((lpSqlNodeValue[0]->value.Timestamp.month - 1) / 3) + 1;
  3158. break;
  3159. case SCALAR_SECOND_CHAR:
  3160. lpstr1 = lpSqlNodeValue[0]->value.String;
  3161. err = CharToTime(lpstr1, s_lstrlen(lpstr1), &sTime);
  3162. if (err != ERR_SUCCESS)
  3163. return err;
  3164. lpSqlNode->value.Double = sTime.second;
  3165. break;
  3166. case SCALAR_SECOND_TIME:
  3167. lpSqlNode->value.Double = lpSqlNodeValue[0]->value.Time.second;
  3168. break;
  3169. case SCALAR_SECOND_TIMESTAMP:
  3170. lpSqlNode->value.Double = lpSqlNodeValue[0]->value.Timestamp.second;
  3171. break;
  3172. case SCALAR_TIMESTAMPADD:
  3173. sw1 = (SWORD) lpSqlNodeValue[0]->value.Double;
  3174. err = MakeTimestamp(lpSqlNodeValue[1], &ts, &t);
  3175. if (err != ERR_SUCCESS)
  3176. return err;
  3177. switch (lpSqlNode->node.scalar.Interval) {
  3178. case SQL_TSI_SECOND:
  3179. ts.tm_sec += (sw1);
  3180. break;
  3181. case SQL_TSI_MINUTE:
  3182. ts.tm_min += (sw1);
  3183. break;
  3184. case SQL_TSI_HOUR:
  3185. ts.tm_hour += (sw1);
  3186. break;
  3187. case SQL_TSI_DAY:
  3188. ts.tm_mday += (sw1);
  3189. break;
  3190. case SQL_TSI_WEEK:
  3191. ts.tm_mday += (sw1 * 7);
  3192. break;
  3193. case SQL_TSI_MONTH:
  3194. ts.tm_mon += (sw1);
  3195. break;
  3196. case SQL_TSI_QUARTER:
  3197. ts.tm_mon += (sw1 * 3);
  3198. break;
  3199. case SQL_TSI_YEAR:
  3200. ts.tm_year += (sw1);
  3201. break;
  3202. default:
  3203. return ERR_INTERNAL;
  3204. }
  3205. if (mktime(&ts) == -1)
  3206. return ERR_NOTCONVERTABLE;
  3207. lpSqlNode->value.Timestamp.month = ts.tm_mon + 1;
  3208. lpSqlNode->value.Timestamp.day = (UWORD) ts.tm_mday;
  3209. lpSqlNode->value.Timestamp.year = ts.tm_year + 1900;
  3210. lpSqlNode->value.Timestamp.hour = (UWORD) ts.tm_hour;
  3211. lpSqlNode->value.Timestamp.minute = (UWORD) ts.tm_min;
  3212. lpSqlNode->value.Timestamp.second = (UWORD) ts.tm_sec;
  3213. lpSqlNode->value.Timestamp.fraction = 0;
  3214. break;
  3215. case SCALAR_TIMESTAMPDIFF:
  3216. err = MakeTimestamp(lpSqlNodeValue[0], &ts, &t);
  3217. if (err != ERR_SUCCESS)
  3218. return err;
  3219. err = MakeTimestamp(lpSqlNodeValue[1], &ts2, &t2);
  3220. if (err != ERR_SUCCESS)
  3221. return err;
  3222. switch (lpSqlNode->node.scalar.Interval) {
  3223. case SQL_TSI_SECOND:
  3224. lpSqlNode->value.Double = t2 - t;
  3225. break;
  3226. case SQL_TSI_MINUTE:
  3227. lpSqlNode->value.Double = (t2 - t)/SECONDS_PER_MINUTE;
  3228. break;
  3229. case SQL_TSI_HOUR:
  3230. lpSqlNode->value.Double = (t2 - t)/SECONDS_PER_HOUR;
  3231. break;
  3232. case SQL_TSI_DAY:
  3233. lpSqlNode->value.Double = (t2 - t)/SECONDS_PER_DAY;
  3234. break;
  3235. case SQL_TSI_WEEK:
  3236. lpSqlNode->value.Double = (t2 - t)/SECONDS_PER_WEEK;
  3237. break;
  3238. case SQL_TSI_MONTH:
  3239. lpSqlNode->value.Double = (ts2.tm_mon - ts.tm_mon) +
  3240. (MONTHS_PER_YEAR * (ts2.tm_year - ts.tm_year));
  3241. break;
  3242. case SQL_TSI_QUARTER:
  3243. lpSqlNode->value.Double = ((ts2.tm_mon - ts.tm_mon) +
  3244. (MONTHS_PER_YEAR * (ts2.tm_year - ts.tm_year))) / 3;
  3245. case SQL_TSI_YEAR:
  3246. lpSqlNode->value.Double = ts2.tm_year - ts.tm_year;
  3247. break;
  3248. default:
  3249. return ERR_INTERNAL;
  3250. }
  3251. break;
  3252. case SCALAR_WEEK:
  3253. err = MakeDate(lpSqlNodeValue[0], &ts);
  3254. if (err != ERR_SUCCESS)
  3255. return err;
  3256. while ((ts.tm_yday > 0) && (ts.tm_wday > 0)) {
  3257. ts.tm_yday--;
  3258. ts.tm_wday--;
  3259. }
  3260. lpSqlNode->value.Double = 1.0;
  3261. while (ts.tm_yday > 6) {
  3262. ts.tm_yday -= (7);
  3263. lpSqlNode->value.Double += (1.0);
  3264. }
  3265. if (ts.tm_yday != 0)
  3266. lpSqlNode->value.Double += (1.0);
  3267. break;
  3268. case SCALAR_YEAR_CHAR:
  3269. lpstr1 = lpSqlNodeValue[0]->value.String;
  3270. err = CharToDate(lpstr1, s_lstrlen(lpstr1), &sDate);
  3271. if (err != ERR_SUCCESS)
  3272. return err;
  3273. lpSqlNode->value.Double = sDate.year;
  3274. break;
  3275. case SCALAR_YEAR_DATE:
  3276. lpSqlNode->value.Double = lpSqlNodeValue[0]->value.Date.year;
  3277. break;
  3278. case SCALAR_YEAR_TIMESTAMP:
  3279. lpSqlNode->value.Double = lpSqlNodeValue[0]->value.Timestamp.year;
  3280. break;
  3281. case SCALAR_DATABASE:
  3282. s_lstrcpy(lpSqlNode->value.String, ISAMDatabase(lpstmt->lpdbc->lpISAM));
  3283. break;
  3284. case SCALAR_IFNULL:
  3285. if (lpSqlNodeValue[0]->sqlIsNull)
  3286. lpSqlNodeReturnValue = lpSqlNodeValue[1];
  3287. else
  3288. lpSqlNodeReturnValue = lpSqlNodeValue[0];
  3289. switch (lpSqlNode->sqlDataType) {
  3290. case TYPE_DOUBLE:
  3291. if (lpSqlNodeReturnValue->sqlIsNull) {
  3292. lpSqlNode->sqlIsNull = TRUE;
  3293. lpSqlNode->value.Double = 0.0;
  3294. }
  3295. else if (lpSqlNodeReturnValue->sqlDataType != TYPE_NUMERIC)
  3296. lpSqlNode->value.Double = lpSqlNodeReturnValue->value.Double;
  3297. else
  3298. CharToDouble(lpSqlNodeReturnValue->value.String,
  3299. s_lstrlen(lpSqlNodeReturnValue->value.String), FALSE,
  3300. DOUBLE_LOW_D, DOUBLE_HIGH_D, &(lpSqlNode->value.Double));
  3301. break;
  3302. case TYPE_NUMERIC:
  3303. if (lpSqlNodeReturnValue->sqlIsNull) {
  3304. lpSqlNode->sqlIsNull = TRUE;
  3305. s_lstrcpy(lpSqlNode->value.String, "");
  3306. }
  3307. else if (lpSqlNodeReturnValue->sqlDataType == TYPE_NUMERIC)
  3308. s_lstrcpy(lpSqlNode->value.String,
  3309. lpSqlNodeReturnValue->value.String);
  3310. else {
  3311. if (DoubleToChar(lpSqlNodeReturnValue->value.Double, FALSE,
  3312. lpSqlNode->value.String,
  3313. 1 + 2 + lpSqlNode->sqlPrecision))
  3314. lpSqlNode->value.String[2 + lpSqlNode->sqlPrecision]='\0';
  3315. }
  3316. BCDNormalize(lpSqlNode->value.String,
  3317. s_lstrlen(lpSqlNode->value.String),
  3318. lpSqlNode->value.String,
  3319. 1 + 2 + lpSqlNode->sqlPrecision,
  3320. lpSqlNode->sqlPrecision,
  3321. lpSqlNode->sqlScale);
  3322. break;
  3323. case TYPE_INTEGER:
  3324. if (lpSqlNodeReturnValue->sqlIsNull) {
  3325. lpSqlNode->sqlIsNull = TRUE;
  3326. lpSqlNode->value.Double = 0.0;
  3327. }
  3328. else
  3329. lpSqlNode->value.Double = lpSqlNodeReturnValue->value.Double;
  3330. break;
  3331. case TYPE_CHAR:
  3332. if (lpSqlNodeReturnValue->sqlIsNull) {
  3333. lpSqlNode->sqlIsNull = TRUE;
  3334. s_lstrcpy(lpSqlNode->value.String, "");
  3335. }
  3336. else {
  3337. s_lstrcpy(lpSqlNode->value.String,
  3338. lpSqlNodeReturnValue->value.String);
  3339. while ((lpSqlNode->sqlSqlType == SQL_CHAR) &&
  3340. (s_lstrlen(lpSqlNode->value.String) <
  3341. lpSqlNode->sqlPrecision))
  3342. s_lstrcat(lpSqlNode->value.String, " ");
  3343. }
  3344. break;
  3345. case TYPE_BINARY:
  3346. if (lpSqlNodeReturnValue->sqlIsNull) {
  3347. lpSqlNode->sqlIsNull = TRUE;
  3348. length = 0;
  3349. }
  3350. else {
  3351. length = (SWORD)
  3352. BINARY_LENGTH(lpSqlNodeReturnValue->value.Binary);
  3353. }
  3354. _fmemcpy(BINARY_DATA(lpSqlNode->value.Binary),
  3355. BINARY_DATA(lpSqlNodeReturnValue->value.Binary),
  3356. length);
  3357. while (!(lpSqlNodeReturnValue->sqlIsNull) &&
  3358. (lpSqlNode->sqlSqlType == SQL_BINARY) &&
  3359. (length < lpSqlNode->sqlPrecision)) {
  3360. lpSqlNode->value.Binary[length] = 0;
  3361. length++;
  3362. }
  3363. BINARY_LENGTH(lpSqlNode->value.Binary) = length;
  3364. break;
  3365. case TYPE_DATE:
  3366. if (lpSqlNodeReturnValue->sqlIsNull) {
  3367. lpSqlNode->sqlIsNull = TRUE;
  3368. lpSqlNode->value.Date.year = 0;
  3369. lpSqlNode->value.Date.month = 0;
  3370. lpSqlNode->value.Date.day = 0;
  3371. }
  3372. else
  3373. lpSqlNode->value.Date = lpSqlNodeReturnValue->value.Date;
  3374. break;
  3375. case TYPE_TIME:
  3376. if (lpSqlNodeReturnValue->sqlIsNull) {
  3377. lpSqlNode->sqlIsNull = TRUE;
  3378. lpSqlNode->value.Time.hour = 0;
  3379. lpSqlNode->value.Time.minute = 0;
  3380. lpSqlNode->value.Time.second = 0;
  3381. }
  3382. else
  3383. lpSqlNode->value.Time = lpSqlNodeReturnValue->value.Time;
  3384. break;
  3385. case TYPE_TIMESTAMP:
  3386. if (lpSqlNodeReturnValue->sqlIsNull) {
  3387. lpSqlNode->sqlIsNull = TRUE;
  3388. lpSqlNode->value.Timestamp.year = 0;
  3389. lpSqlNode->value.Timestamp.month = 0;
  3390. lpSqlNode->value.Timestamp.day = 0;
  3391. lpSqlNode->value.Timestamp.hour = 0;
  3392. lpSqlNode->value.Timestamp.minute = 0;
  3393. lpSqlNode->value.Timestamp.second = 0;
  3394. lpSqlNode->value.Timestamp.fraction = 0;
  3395. }
  3396. else
  3397. lpSqlNode->value.Timestamp = lpSqlNodeReturnValue->value.Timestamp;
  3398. break;
  3399. default:
  3400. return ERR_INTERNAL;
  3401. }
  3402. break;
  3403. case SCALAR_USER:
  3404. s_lstrcpy(lpSqlNode->value.String, ISAMUser(lpstmt->lpdbc->lpISAM));
  3405. break;
  3406. case SCALAR_CONVERT:
  3407. switch (lpSqlNode->sqlSqlType) {
  3408. case SQL_CHAR:
  3409. case SQL_VARCHAR:
  3410. switch (lpSqlNodeValue[0]->sqlSqlType) {
  3411. case SQL_CHAR:
  3412. case SQL_VARCHAR:
  3413. case SQL_DECIMAL:
  3414. case SQL_NUMERIC:
  3415. case SQL_BIGINT:
  3416. s_lstrcpy(lpSqlNode->value.String,
  3417. lpSqlNodeValue[0]->value.String);
  3418. if ((lpSqlNode->sqlSqlType == SQL_VARCHAR) &&
  3419. (lpSqlNodeValue[0]->sqlSqlType == SQL_CHAR)) {
  3420. length = (SWORD) s_lstrlen(lpSqlNode->value.String);
  3421. while ((length > 0) &&
  3422. (lpSqlNode->value.String[length-1] == ' ')) {
  3423. lpSqlNode->value.String[length-1] = '\0';
  3424. length--;
  3425. }
  3426. }
  3427. break;
  3428. case SQL_LONGVARCHAR:
  3429. case SQL_LONGVARBINARY:
  3430. return ERR_NOTSUPPORTED;
  3431. case SQL_BIT:
  3432. case SQL_TINYINT:
  3433. case SQL_SMALLINT:
  3434. case SQL_INTEGER:
  3435. case SQL_REAL:
  3436. case SQL_FLOAT:
  3437. case SQL_DOUBLE:
  3438. if (DoubleToChar(lpSqlNodeValue[0]->value.Double, TRUE,
  3439. lpSqlNode->value.String, lpSqlNode->sqlPrecision))
  3440. lpSqlNode->value.String[lpSqlNode->sqlPrecision-1] = '\0';
  3441. break;
  3442. case SQL_BINARY:
  3443. case SQL_VARBINARY:
  3444. /* Figure out how many nibbles (not bytes) to copy */
  3445. length = (SWORD) (2 *
  3446. BINARY_LENGTH(lpSqlNodeValue[0]->value.Binary));
  3447. if (length > lpSqlNode->sqlPrecision)
  3448. return ERR_NOTCONVERTABLE;
  3449. /* Copy the value */
  3450. lpFrom = BINARY_DATA(lpSqlNodeValue[0]->value.Binary);
  3451. lpTo = BINARY_DATA(lpSqlNode->value.Binary);
  3452. for (idx = 0; idx < (UWORD) length; idx++) {
  3453. /* Get the next nibble */
  3454. nibble = *lpFrom;
  3455. if (((idx/2) * 2) == idx)
  3456. nibble = nibble >> 4;
  3457. else
  3458. lpFrom++;
  3459. nibble = nibble & 0x0F;
  3460. /* Convert it to a character */
  3461. if (nibble <= 9)
  3462. *lpTo = nibble + '0';
  3463. else
  3464. *lpTo = (nibble-10) + 'A';
  3465. lpTo++;
  3466. }
  3467. *lpTo = '\0';
  3468. break;
  3469. case SQL_DATE:
  3470. DateToChar(&(lpSqlNodeValue[0]->value.Date),
  3471. lpSqlNode->value.String);
  3472. break;
  3473. case SQL_TIME:
  3474. TimeToChar(&(lpSqlNodeValue[0]->value.Time),
  3475. lpSqlNode->value.String);
  3476. break;
  3477. case SQL_TIMESTAMP:
  3478. TimestampToChar(&(lpSqlNodeValue[0]->value.Timestamp),
  3479. lpSqlNode->value.String);
  3480. break;
  3481. default:
  3482. return ERR_NOTSUPPORTED;
  3483. }
  3484. if (lpSqlNode->sqlSqlType == SQL_CHAR) {
  3485. while (s_lstrlen(lpSqlNode->value.String) <
  3486. lpSqlNode->sqlPrecision)
  3487. s_lstrcat(lpSqlNode->value.String, " ");
  3488. }
  3489. break;
  3490. case SQL_LONGVARCHAR:
  3491. case SQL_LONGVARBINARY:
  3492. return ERR_NOTSUPPORTED;
  3493. case SQL_BIT:
  3494. switch (lpSqlNodeValue[0]->sqlSqlType) {
  3495. case SQL_CHAR:
  3496. case SQL_VARCHAR:
  3497. case SQL_DECIMAL:
  3498. case SQL_NUMERIC:
  3499. case SQL_BIGINT:
  3500. err = CharToDouble(lpSqlNodeValue[0]->value.String,
  3501. s_lstrlen(lpSqlNodeValue[0]->value.String),
  3502. TRUE, BIT_LOW_D, BIT_HIGH_D,
  3503. &(lpSqlNode->value.Double));
  3504. if (err != ERR_SUCCESS) {
  3505. if (err == ERR_OUTOFRANGE)
  3506. return ERR_OUTOFRANGE;
  3507. else
  3508. return ERR_NOTCONVERTABLE;
  3509. }
  3510. break;
  3511. case SQL_LONGVARCHAR:
  3512. case SQL_LONGVARBINARY:
  3513. return ERR_NOTSUPPORTED;
  3514. case SQL_BIT:
  3515. case SQL_TINYINT:
  3516. case SQL_SMALLINT:
  3517. case SQL_INTEGER:
  3518. case SQL_REAL:
  3519. case SQL_FLOAT:
  3520. case SQL_DOUBLE:
  3521. lpSqlNode->value.Double = lpSqlNodeValue[0]->value.Double;
  3522. if ((lpSqlNode->value.Double < BIT_LOW_D) ||
  3523. (lpSqlNode->value.Double > BIT_HIGH_D))
  3524. return ERR_OUTOFRANGE;
  3525. break;
  3526. case SQL_BINARY:
  3527. case SQL_VARBINARY:
  3528. if (BINARY_LENGTH(lpSqlNodeValue[0]->value.Binary) !=
  3529. sizeof(unsigned char))
  3530. return ERR_NOTCONVERTABLE;
  3531. lpSqlNode->value.Double = *((unsigned char far *)
  3532. BINARY_DATA(lpSqlNodeValue[0]->value.Binary));
  3533. if ((lpSqlNode->value.Double < BIT_LOW_D) ||
  3534. (lpSqlNode->value.Double > BIT_HIGH_D))
  3535. return ERR_OUTOFRANGE;
  3536. break;
  3537. case SQL_DATE:
  3538. case SQL_TIME:
  3539. case SQL_TIMESTAMP:
  3540. return ERR_NOTCONVERTABLE;
  3541. default:
  3542. return ERR_NOTSUPPORTED;
  3543. }
  3544. break;
  3545. case SQL_TINYINT:
  3546. switch (lpSqlNodeValue[0]->sqlSqlType) {
  3547. case SQL_CHAR:
  3548. case SQL_VARCHAR:
  3549. case SQL_DECIMAL:
  3550. case SQL_NUMERIC:
  3551. case SQL_BIGINT:
  3552. err = CharToDouble(lpSqlNodeValue[0]->value.String,
  3553. s_lstrlen(lpSqlNodeValue[0]->value.String),
  3554. TRUE, STINY_LOW_D, STINY_LOW_D,
  3555. &(lpSqlNode->value.Double));
  3556. if (err != ERR_SUCCESS) {
  3557. if (err == ERR_OUTOFRANGE)
  3558. return ERR_OUTOFRANGE;
  3559. else
  3560. return ERR_NOTCONVERTABLE;
  3561. }
  3562. break;
  3563. case SQL_LONGVARCHAR:
  3564. case SQL_LONGVARBINARY:
  3565. return ERR_NOTSUPPORTED;
  3566. case SQL_BIT:
  3567. case SQL_TINYINT:
  3568. case SQL_SMALLINT:
  3569. case SQL_INTEGER:
  3570. case SQL_REAL:
  3571. case SQL_FLOAT:
  3572. case SQL_DOUBLE:
  3573. lpSqlNode->value.Double = lpSqlNodeValue[0]->value.Double;
  3574. if ((lpSqlNode->value.Double < STINY_LOW_D) ||
  3575. (lpSqlNode->value.Double > STINY_HIGH_D))
  3576. return ERR_OUTOFRANGE;
  3577. break;
  3578. case SQL_BINARY:
  3579. case SQL_VARBINARY:
  3580. if (BINARY_LENGTH(lpSqlNodeValue[0]->value.Binary) !=
  3581. sizeof(char))
  3582. return ERR_NOTCONVERTABLE;
  3583. lpSqlNode->value.Double = *((char far *)
  3584. BINARY_DATA(lpSqlNodeValue[0]->value.Binary));
  3585. if ((lpSqlNode->value.Double < BIT_LOW_D) ||
  3586. (lpSqlNode->value.Double > BIT_HIGH_D))
  3587. return ERR_OUTOFRANGE;
  3588. break;
  3589. case SQL_DATE:
  3590. case SQL_TIME:
  3591. case SQL_TIMESTAMP:
  3592. return ERR_NOTCONVERTABLE;
  3593. default:
  3594. return ERR_NOTSUPPORTED;
  3595. }
  3596. break;
  3597. case SQL_SMALLINT:
  3598. switch (lpSqlNodeValue[0]->sqlSqlType) {
  3599. case SQL_CHAR:
  3600. case SQL_VARCHAR:
  3601. case SQL_DECIMAL:
  3602. case SQL_NUMERIC:
  3603. case SQL_BIGINT:
  3604. err = CharToDouble(lpSqlNodeValue[0]->value.String,
  3605. s_lstrlen(lpSqlNodeValue[0]->value.String),
  3606. TRUE, SSHORT_LOW_D, SSHORT_HIGH_D,
  3607. &(lpSqlNode->value.Double));
  3608. if (err != ERR_SUCCESS) {
  3609. if (err == ERR_OUTOFRANGE)
  3610. return ERR_OUTOFRANGE;
  3611. else
  3612. return ERR_NOTCONVERTABLE;
  3613. }
  3614. break;
  3615. case SQL_LONGVARCHAR:
  3616. case SQL_LONGVARBINARY:
  3617. return ERR_NOTSUPPORTED;
  3618. case SQL_BIT:
  3619. case SQL_TINYINT:
  3620. case SQL_SMALLINT:
  3621. case SQL_INTEGER:
  3622. case SQL_REAL:
  3623. case SQL_FLOAT:
  3624. case SQL_DOUBLE:
  3625. lpSqlNode->value.Double = lpSqlNodeValue[0]->value.Double;
  3626. if ((lpSqlNode->value.Double < SSHORT_LOW_D) ||
  3627. (lpSqlNode->value.Double > SSHORT_HIGH_D))
  3628. return ERR_OUTOFRANGE;
  3629. break;
  3630. case SQL_BINARY:
  3631. case SQL_VARBINARY:
  3632. if (BINARY_LENGTH(lpSqlNodeValue[0]->value.Binary) !=
  3633. sizeof(short))
  3634. return ERR_NOTCONVERTABLE;
  3635. lpSqlNode->value.Double = *((short far *)
  3636. BINARY_DATA(lpSqlNodeValue[0]->value.Binary));
  3637. if ((lpSqlNode->value.Double < BIT_LOW_D) ||
  3638. (lpSqlNode->value.Double > BIT_HIGH_D))
  3639. return ERR_OUTOFRANGE;
  3640. break;
  3641. case SQL_DATE:
  3642. case SQL_TIME:
  3643. case SQL_TIMESTAMP:
  3644. return ERR_NOTCONVERTABLE;
  3645. default:
  3646. return ERR_NOTSUPPORTED;
  3647. }
  3648. break;
  3649. case SQL_INTEGER:
  3650. switch (lpSqlNodeValue[0]->sqlSqlType) {
  3651. case SQL_CHAR:
  3652. case SQL_VARCHAR:
  3653. case SQL_DECIMAL:
  3654. case SQL_NUMERIC:
  3655. case SQL_BIGINT:
  3656. err = CharToDouble(lpSqlNodeValue[0]->value.String,
  3657. s_lstrlen(lpSqlNodeValue[0]->value.String),
  3658. TRUE, SLONG_LOW_D, SLONG_HIGH_D,
  3659. &(lpSqlNode->value.Double));
  3660. if (err != ERR_SUCCESS) {
  3661. if (err == ERR_OUTOFRANGE)
  3662. return ERR_OUTOFRANGE;
  3663. else
  3664. return ERR_NOTCONVERTABLE;
  3665. }
  3666. break;
  3667. case SQL_LONGVARCHAR:
  3668. case SQL_LONGVARBINARY:
  3669. return ERR_NOTSUPPORTED;
  3670. case SQL_BIT:
  3671. case SQL_TINYINT:
  3672. case SQL_SMALLINT:
  3673. case SQL_INTEGER:
  3674. case SQL_REAL:
  3675. case SQL_FLOAT:
  3676. case SQL_DOUBLE:
  3677. lpSqlNode->value.Double = lpSqlNodeValue[0]->value.Double;
  3678. if ((lpSqlNode->value.Double < SLONG_LOW_D) ||
  3679. (lpSqlNode->value.Double > SLONG_HIGH_D))
  3680. return ERR_OUTOFRANGE;
  3681. break;
  3682. case SQL_BINARY:
  3683. case SQL_VARBINARY:
  3684. if (BINARY_LENGTH(lpSqlNodeValue[0]->value.Binary) !=
  3685. sizeof(long))
  3686. return ERR_NOTCONVERTABLE;
  3687. lpSqlNode->value.Double = *((long far *)
  3688. BINARY_DATA(lpSqlNodeValue[0]->value.Binary));
  3689. if ((lpSqlNode->value.Double < BIT_LOW_D) ||
  3690. (lpSqlNode->value.Double > BIT_HIGH_D))
  3691. return ERR_OUTOFRANGE;
  3692. break;
  3693. case SQL_DATE:
  3694. case SQL_TIME:
  3695. case SQL_TIMESTAMP:
  3696. return ERR_NOTCONVERTABLE;
  3697. default:
  3698. return ERR_NOTSUPPORTED;
  3699. }
  3700. break;
  3701. case SQL_REAL:
  3702. switch (lpSqlNodeValue[0]->sqlSqlType) {
  3703. case SQL_CHAR:
  3704. case SQL_VARCHAR:
  3705. case SQL_DECIMAL:
  3706. case SQL_NUMERIC:
  3707. case SQL_BIGINT:
  3708. err = CharToDouble(lpSqlNodeValue[0]->value.String,
  3709. s_lstrlen(lpSqlNodeValue[0]->value.String),
  3710. FALSE, FLOAT_LOW_D, FLOAT_HIGH_D,
  3711. &(lpSqlNode->value.Double));
  3712. if (err != ERR_SUCCESS) {
  3713. if (err == ERR_OUTOFRANGE)
  3714. return ERR_OUTOFRANGE;
  3715. else
  3716. return ERR_NOTCONVERTABLE;
  3717. }
  3718. break;
  3719. case SQL_LONGVARCHAR:
  3720. case SQL_LONGVARBINARY:
  3721. return ERR_NOTSUPPORTED;
  3722. case SQL_BIT:
  3723. case SQL_TINYINT:
  3724. case SQL_SMALLINT:
  3725. case SQL_INTEGER:
  3726. case SQL_REAL:
  3727. case SQL_FLOAT:
  3728. case SQL_DOUBLE:
  3729. lpSqlNode->value.Double = lpSqlNodeValue[0]->value.Double;
  3730. if ((lpSqlNode->value.Double < FLOAT_LOW_D) ||
  3731. (lpSqlNode->value.Double > FLOAT_HIGH_D))
  3732. return ERR_OUTOFRANGE;
  3733. break;
  3734. case SQL_BINARY:
  3735. case SQL_VARBINARY:
  3736. if (BINARY_LENGTH(lpSqlNodeValue[0]->value.Binary) !=
  3737. sizeof(float))
  3738. return ERR_NOTCONVERTABLE;
  3739. lpSqlNode->value.Double = *((float far *)
  3740. BINARY_DATA(lpSqlNodeValue[0]->value.Binary));
  3741. if ((lpSqlNode->value.Double < BIT_LOW_D) ||
  3742. (lpSqlNode->value.Double > BIT_HIGH_D))
  3743. return ERR_OUTOFRANGE;
  3744. break;
  3745. case SQL_DATE:
  3746. case SQL_TIME:
  3747. case SQL_TIMESTAMP:
  3748. return ERR_NOTCONVERTABLE;
  3749. default:
  3750. return ERR_NOTSUPPORTED;
  3751. }
  3752. break;
  3753. case SQL_FLOAT:
  3754. case SQL_DOUBLE:
  3755. switch (lpSqlNodeValue[0]->sqlSqlType) {
  3756. case SQL_CHAR:
  3757. case SQL_VARCHAR:
  3758. case SQL_DECIMAL:
  3759. case SQL_NUMERIC:
  3760. case SQL_BIGINT:
  3761. err = CharToDouble(lpSqlNodeValue[0]->value.String,
  3762. s_lstrlen(lpSqlNodeValue[0]->value.String),
  3763. FALSE, DOUBLE_LOW_D, DOUBLE_HIGH_D,
  3764. &(lpSqlNode->value.Double));
  3765. if (err != ERR_SUCCESS) {
  3766. if (err == ERR_OUTOFRANGE)
  3767. return ERR_OUTOFRANGE;
  3768. else
  3769. return ERR_NOTCONVERTABLE;
  3770. }
  3771. break;
  3772. case SQL_LONGVARCHAR:
  3773. case SQL_LONGVARBINARY:
  3774. return ERR_NOTSUPPORTED;
  3775. case SQL_BIT:
  3776. case SQL_TINYINT:
  3777. case SQL_SMALLINT:
  3778. case SQL_INTEGER:
  3779. case SQL_REAL:
  3780. case SQL_FLOAT:
  3781. case SQL_DOUBLE:
  3782. lpSqlNode->value.Double = lpSqlNodeValue[0]->value.Double;
  3783. if ((lpSqlNode->value.Double < DOUBLE_LOW_D) ||
  3784. (lpSqlNode->value.Double > DOUBLE_HIGH_D))
  3785. return ERR_OUTOFRANGE;
  3786. break;
  3787. case SQL_BINARY:
  3788. case SQL_VARBINARY:
  3789. if (BINARY_LENGTH(lpSqlNodeValue[0]->value.Binary) !=
  3790. sizeof(double))
  3791. return ERR_NOTCONVERTABLE;
  3792. lpSqlNode->value.Double = *((double far *)
  3793. BINARY_DATA(lpSqlNodeValue[0]->value.Binary));
  3794. if ((lpSqlNode->value.Double < BIT_LOW_D) ||
  3795. (lpSqlNode->value.Double > BIT_HIGH_D))
  3796. return ERR_OUTOFRANGE;
  3797. break;
  3798. case SQL_DATE:
  3799. case SQL_TIME:
  3800. case SQL_TIMESTAMP:
  3801. return ERR_NOTCONVERTABLE;
  3802. default:
  3803. return ERR_NOTSUPPORTED;
  3804. }
  3805. break;
  3806. case SQL_DECIMAL:
  3807. case SQL_NUMERIC:
  3808. case SQL_BIGINT:
  3809. switch (lpSqlNodeValue[0]->sqlSqlType) {
  3810. case SQL_CHAR:
  3811. case SQL_VARCHAR:
  3812. err = CharToDouble(lpSqlNodeValue[0]->value.String,
  3813. s_lstrlen(lpSqlNodeValue[0]->value.String),
  3814. FALSE, DOUBLE_LOW_D, DOUBLE_HIGH_D, &dbl);
  3815. if (err != ERR_SUCCESS) {
  3816. if (err == ERR_OUTOFRANGE)
  3817. return ERR_OUTOFRANGE;
  3818. else
  3819. return ERR_NOTCONVERTABLE;
  3820. }
  3821. s_lstrcpy(lpSqlNode->value.String,
  3822. lpSqlNodeValue[0]->value.String);
  3823. break;
  3824. case SQL_DECIMAL:
  3825. case SQL_NUMERIC:
  3826. case SQL_BIGINT:
  3827. s_lstrcpy(lpSqlNode->value.String,
  3828. lpSqlNodeValue[0]->value.String);
  3829. break;
  3830. case SQL_LONGVARCHAR:
  3831. case SQL_LONGVARBINARY:
  3832. return ERR_NOTSUPPORTED;
  3833. case SQL_BIT:
  3834. case SQL_TINYINT:
  3835. case SQL_SMALLINT:
  3836. case SQL_INTEGER:
  3837. case SQL_REAL:
  3838. case SQL_FLOAT:
  3839. case SQL_DOUBLE:
  3840. if (DoubleToChar(lpSqlNodeValue[0]->value.Double, FALSE,
  3841. lpSqlNode->value.String,
  3842. lpSqlNode->sqlPrecision + 2 + 1))
  3843. lpSqlNode->value.String[2 + lpSqlNode->sqlPrecision]='\0';
  3844. break;
  3845. case SQL_BINARY:
  3846. case SQL_VARBINARY:
  3847. err = CharToDouble(
  3848. BINARY_DATA(lpSqlNodeValue[0]->value.Binary),
  3849. BINARY_LENGTH(lpSqlNodeValue[0]->value.Binary),
  3850. FALSE, DOUBLE_LOW_D, DOUBLE_HIGH_D, &dbl);
  3851. if (err != ERR_SUCCESS) {
  3852. if (err == ERR_OUTOFRANGE)
  3853. return ERR_OUTOFRANGE;
  3854. else
  3855. return ERR_NOTCONVERTABLE;
  3856. }
  3857. _fmemcpy(lpSqlNode->value.String,
  3858. BINARY_DATA(lpSqlNodeValue[0]->value.Binary),
  3859. (SWORD) BINARY_LENGTH(lpSqlNodeValue[0]->value.Binary));
  3860. lpSqlNode->value.String[
  3861. BINARY_LENGTH(lpSqlNodeValue[0]->value.Binary)] = '\0';
  3862. break;
  3863. case SQL_DATE:
  3864. case SQL_TIME:
  3865. case SQL_TIMESTAMP:
  3866. return ERR_NOTCONVERTABLE;
  3867. default:
  3868. return ERR_NOTSUPPORTED;
  3869. }
  3870. err = BCDNormalize(lpSqlNode->value.String,
  3871. s_lstrlen(lpSqlNode->value.String),
  3872. lpSqlNode->value.String,
  3873. 1 + 2 + lpSqlNode->sqlPrecision,
  3874. lpSqlNode->sqlPrecision,
  3875. lpSqlNode->sqlScale);
  3876. if ((err != ERR_SUCCESS) && (err != ERR_DATATRUNCATED))
  3877. return err;
  3878. break;
  3879. case SQL_BINARY:
  3880. case SQL_VARBINARY:
  3881. switch (lpSqlNodeValue[0]->sqlSqlType) {
  3882. case SQL_CHAR:
  3883. case SQL_VARCHAR:
  3884. case SQL_DECIMAL:
  3885. case SQL_NUMERIC:
  3886. case SQL_BIGINT:
  3887. _fmemcpy(BINARY_DATA(lpSqlNode->value.Binary),
  3888. lpSqlNodeValue[0]->value.String,
  3889. s_lstrlen(lpSqlNodeValue[0]->value.String));
  3890. BINARY_LENGTH(lpSqlNode->value.Binary) =
  3891. s_lstrlen(lpSqlNodeValue[0]->value.String);
  3892. break;
  3893. case SQL_LONGVARCHAR:
  3894. case SQL_LONGVARBINARY:
  3895. return ERR_NOTSUPPORTED;
  3896. case SQL_BIT:
  3897. uchr = (unsigned char) lpSqlNodeValue[0]->value.Double;
  3898. _fmemcpy(BINARY_DATA(lpSqlNode->value.Binary),
  3899. &uchr, sizeof(unsigned char));
  3900. BINARY_LENGTH(lpSqlNode->value.Binary) =
  3901. sizeof(unsigned char);
  3902. break;
  3903. case SQL_TINYINT:
  3904. chr = (char) lpSqlNodeValue[0]->value.Double;
  3905. _fmemcpy(BINARY_DATA(lpSqlNode->value.Binary),
  3906. &chr, sizeof(char));
  3907. BINARY_LENGTH(lpSqlNode->value.Binary) = sizeof(char);
  3908. break;
  3909. case SQL_SMALLINT:
  3910. shrt = (short) lpSqlNodeValue[0]->value.Double;
  3911. _fmemcpy(BINARY_DATA(lpSqlNode->value.Binary),
  3912. &shrt, sizeof(short));
  3913. BINARY_LENGTH(lpSqlNode->value.Binary) = sizeof(short);
  3914. break;
  3915. case SQL_INTEGER:
  3916. lng = (long) lpSqlNodeValue[0]->value.Double;
  3917. _fmemcpy(BINARY_DATA(lpSqlNode->value.Binary),
  3918. &lng, sizeof(long));
  3919. BINARY_LENGTH(lpSqlNode->value.Binary) = sizeof(long);
  3920. break;
  3921. case SQL_REAL:
  3922. flt = (float) lpSqlNodeValue[0]->value.Double;
  3923. _fmemcpy(BINARY_DATA(lpSqlNode->value.Binary),
  3924. &flt, sizeof(float));
  3925. BINARY_LENGTH(lpSqlNode->value.Binary) = sizeof(float);
  3926. break;
  3927. case SQL_FLOAT:
  3928. case SQL_DOUBLE:
  3929. _fmemcpy(BINARY_DATA(lpSqlNode->value.Binary),
  3930. &(lpSqlNodeValue[0]->value.Double), sizeof(double));
  3931. BINARY_LENGTH(lpSqlNode->value.Binary) = sizeof(double);
  3932. break;
  3933. case SQL_BINARY:
  3934. case SQL_VARBINARY:
  3935. _fmemcpy(BINARY_DATA(lpSqlNode->value.Binary),
  3936. BINARY_DATA(lpSqlNodeValue[0]->value.Binary),
  3937. (SWORD) BINARY_LENGTH(lpSqlNodeValue[0]->value.Binary));
  3938. BINARY_LENGTH(lpSqlNode->value.Binary) =
  3939. BINARY_LENGTH(lpSqlNodeValue[0]->value.Binary);
  3940. break;
  3941. case SQL_DATE:
  3942. _fmemcpy(BINARY_DATA(lpSqlNode->value.Binary),
  3943. &(lpSqlNodeValue[0]->value.Date), sizeof(DATE_STRUCT));
  3944. BINARY_LENGTH(lpSqlNode->value.Binary) = sizeof(DATE_STRUCT);
  3945. break;
  3946. case SQL_TIME:
  3947. _fmemcpy(BINARY_DATA(lpSqlNode->value.Binary),
  3948. &(lpSqlNodeValue[0]->value.Time), sizeof(TIME_STRUCT));
  3949. BINARY_LENGTH(lpSqlNode->value.Binary) = sizeof(TIME_STRUCT);
  3950. break;
  3951. case SQL_TIMESTAMP:
  3952. _fmemcpy(BINARY_DATA(lpSqlNode->value.Binary),
  3953. &(lpSqlNodeValue[0]->value.Timestamp),
  3954. sizeof(TIMESTAMP_STRUCT));
  3955. BINARY_LENGTH(lpSqlNode->value.Binary) =
  3956. sizeof(TIMESTAMP_STRUCT);
  3957. break;
  3958. default:
  3959. return ERR_NOTSUPPORTED;
  3960. }
  3961. if (lpSqlNode->sqlSqlType == SQL_BINARY) {
  3962. while (BINARY_LENGTH(lpSqlNode->value.Binary) <
  3963. lpSqlNode->sqlPrecision) {
  3964. BINARY_DATA(lpSqlNode->value.Binary)
  3965. [BINARY_LENGTH(lpSqlNode->value.Binary)] = '\0';
  3966. BINARY_LENGTH(lpSqlNode->value.Binary) += (1);
  3967. }
  3968. }
  3969. break;
  3970. case SQL_DATE:
  3971. switch (lpSqlNodeValue[0]->sqlSqlType) {
  3972. case SQL_CHAR:
  3973. case SQL_VARCHAR:
  3974. err = CharToDate(lpSqlNodeValue[0]->value.String,
  3975. s_lstrlen(lpSqlNodeValue[0]->value.String),
  3976. &(lpSqlNode->value.Date));
  3977. if (err != ERR_SUCCESS)
  3978. return err;
  3979. break;
  3980. case SQL_LONGVARCHAR:
  3981. case SQL_LONGVARBINARY:
  3982. return ERR_NOTSUPPORTED;
  3983. case SQL_BIT:
  3984. case SQL_TINYINT:
  3985. case SQL_SMALLINT:
  3986. case SQL_INTEGER:
  3987. case SQL_REAL:
  3988. case SQL_DECIMAL:
  3989. case SQL_NUMERIC:
  3990. case SQL_BIGINT:
  3991. case SQL_FLOAT:
  3992. case SQL_DOUBLE:
  3993. return ERR_NOTCONVERTABLE;
  3994. case SQL_BINARY:
  3995. case SQL_VARBINARY:
  3996. if (BINARY_LENGTH(lpSqlNodeValue[0]->value.Binary) !=
  3997. sizeof(DATE_STRUCT))
  3998. return ERR_NOTCONVERTABLE;
  3999. lpSqlNode->value.Date = *((DATE_STRUCT far *)
  4000. BINARY_DATA(lpSqlNodeValue[0]->value.Binary));
  4001. break;
  4002. case SQL_DATE:
  4003. lpSqlNode->value.Date = lpSqlNodeValue[0]->value.Date;
  4004. break;
  4005. case SQL_TIME:
  4006. return ERR_NOTCONVERTABLE;
  4007. case SQL_TIMESTAMP:
  4008. lpSqlNode->value.Date.year =
  4009. lpSqlNodeValue[0]->value.Timestamp.year;
  4010. lpSqlNode->value.Date.month =
  4011. lpSqlNodeValue[0]->value.Timestamp.month;
  4012. lpSqlNode->value.Date.day =
  4013. lpSqlNodeValue[0]->value.Timestamp.day;
  4014. break;
  4015. default:
  4016. return ERR_NOTSUPPORTED;
  4017. }
  4018. break;
  4019. case SQL_TIME:
  4020. switch (lpSqlNodeValue[0]->sqlSqlType) {
  4021. case SQL_CHAR:
  4022. case SQL_VARCHAR:
  4023. err = CharToTime(lpSqlNodeValue[0]->value.String,
  4024. s_lstrlen(lpSqlNodeValue[0]->value.String),
  4025. &(lpSqlNode->value.Time));
  4026. if (err != ERR_SUCCESS)
  4027. return err;
  4028. break;
  4029. case SQL_LONGVARCHAR:
  4030. case SQL_LONGVARBINARY:
  4031. return ERR_NOTSUPPORTED;
  4032. case SQL_BIT:
  4033. case SQL_TINYINT:
  4034. case SQL_SMALLINT:
  4035. case SQL_INTEGER:
  4036. case SQL_REAL:
  4037. case SQL_DECIMAL:
  4038. case SQL_NUMERIC:
  4039. case SQL_BIGINT:
  4040. case SQL_FLOAT:
  4041. case SQL_DOUBLE:
  4042. return ERR_NOTCONVERTABLE;
  4043. case SQL_BINARY:
  4044. case SQL_VARBINARY:
  4045. if (BINARY_LENGTH(lpSqlNodeValue[0]->value.Binary) !=
  4046. sizeof(TIME_STRUCT))
  4047. return ERR_NOTCONVERTABLE;
  4048. lpSqlNode->value.Time = *((TIME_STRUCT far *)
  4049. BINARY_DATA(lpSqlNodeValue[0]->value.Binary));
  4050. break;
  4051. case SQL_DATE:
  4052. return ERR_NOTCONVERTABLE;
  4053. case SQL_TIME:
  4054. lpSqlNode->value.Time = lpSqlNodeValue[0]->value.Time;
  4055. break;
  4056. case SQL_TIMESTAMP:
  4057. lpSqlNode->value.Time.hour =
  4058. lpSqlNodeValue[0]->value.Timestamp.hour;
  4059. lpSqlNode->value.Time.minute =
  4060. lpSqlNodeValue[0]->value.Timestamp.minute;
  4061. lpSqlNode->value.Time.second =
  4062. lpSqlNodeValue[0]->value.Timestamp.second;
  4063. break;
  4064. default:
  4065. return ERR_NOTSUPPORTED;
  4066. }
  4067. break;
  4068. case SQL_TIMESTAMP:
  4069. switch (lpSqlNodeValue[0]->sqlSqlType) {
  4070. case SQL_CHAR:
  4071. case SQL_VARCHAR:
  4072. err = CharToTimestamp(lpSqlNodeValue[0]->value.String,
  4073. s_lstrlen(lpSqlNodeValue[0]->value.String),
  4074. &(lpSqlNode->value.Timestamp));
  4075. if (err != ERR_SUCCESS)
  4076. return err;
  4077. break;
  4078. case SQL_LONGVARCHAR:
  4079. case SQL_LONGVARBINARY:
  4080. return ERR_NOTSUPPORTED;
  4081. case SQL_BIT:
  4082. case SQL_TINYINT:
  4083. case SQL_SMALLINT:
  4084. case SQL_INTEGER:
  4085. case SQL_REAL:
  4086. case SQL_DECIMAL:
  4087. case SQL_NUMERIC:
  4088. case SQL_BIGINT:
  4089. case SQL_FLOAT:
  4090. case SQL_DOUBLE:
  4091. return ERR_NOTCONVERTABLE;
  4092. case SQL_BINARY:
  4093. case SQL_VARBINARY:
  4094. if (BINARY_LENGTH(lpSqlNodeValue[0]->value.Binary) !=
  4095. sizeof(TIMESTAMP_STRUCT))
  4096. return ERR_NOTCONVERTABLE;
  4097. lpSqlNode->value.Timestamp = *((TIMESTAMP_STRUCT far *)
  4098. BINARY_DATA(lpSqlNodeValue[0]->value.Binary));
  4099. break;
  4100. case SQL_DATE:
  4101. lpSqlNode->value.Timestamp.year =
  4102. lpSqlNodeValue[0]->value.Date.year;
  4103. lpSqlNode->value.Timestamp.month =
  4104. lpSqlNodeValue[0]->value.Date.month;
  4105. lpSqlNode->value.Timestamp.day =
  4106. lpSqlNodeValue[0]->value.Date.day;
  4107. lpSqlNode->value.Timestamp.hour = 0;
  4108. lpSqlNode->value.Timestamp.minute = 0;
  4109. lpSqlNode->value.Timestamp.second = 0;
  4110. lpSqlNode->value.Timestamp.fraction = 0;
  4111. break;
  4112. case SQL_TIME:
  4113. time(&t);
  4114. lpTs = localtime(&t);
  4115. lpSqlNode->value.Timestamp.year = lpTs->tm_year + 1900;
  4116. lpSqlNode->value.Timestamp.month = lpTs->tm_mon + 1;
  4117. lpSqlNode->value.Timestamp.day = (UWORD) lpTs->tm_mday;
  4118. lpSqlNode->value.Timestamp.hour =
  4119. lpSqlNodeValue[0]->value.Time.hour;
  4120. lpSqlNode->value.Timestamp.minute =
  4121. lpSqlNodeValue[0]->value.Time.minute;
  4122. lpSqlNode->value.Timestamp.second =
  4123. lpSqlNodeValue[0]->value.Time.second;
  4124. lpSqlNode->value.Timestamp.fraction = 0;
  4125. break;
  4126. case SQL_TIMESTAMP:
  4127. lpSqlNode->value.Timestamp =
  4128. lpSqlNodeValue[0]->value.Timestamp;
  4129. break;
  4130. default:
  4131. return ERR_NOTSUPPORTED;
  4132. }
  4133. break;
  4134. default:
  4135. return ERR_NOTSUPPORTED;
  4136. }
  4137. break;
  4138. default:
  4139. return ERR_INTERNAL;
  4140. }
  4141. return ERR_SUCCESS;
  4142. }
  4143. /***************************************************************************/
  4144. #ifndef WIN32
  4145. void ScalarExceptionHandler(int sig)
  4146. {
  4147. _fpreset();
  4148. longjmp(scalarExceptionMark, -1);
  4149. }
  4150. #endif
  4151. /***************************************************************************/
  4152. RETCODE INTFUNC EvaluateScalar(LPSTMT lpstmt, LPSQLNODE lpSqlNode)
  4153. {
  4154. RETCODE err;
  4155. #ifndef WIN32
  4156. void (__cdecl *func)(int);
  4157. int jmpret;
  4158. #endif
  4159. #ifdef WIN32
  4160. __try {
  4161. #else
  4162. func = signal(SIGFPE, ScalarExceptionHandler);
  4163. if (func != SIG_ERR)
  4164. jmpret = setjmp(scalarExceptionMark);
  4165. if ((func != SIG_ERR) && (jmpret == 0)) {
  4166. #endif
  4167. err = InternalEvaluateScalar(lpstmt, lpSqlNode);
  4168. }
  4169. #ifdef WIN32
  4170. __except(EXCEPTION_EXECUTE_HANDLER) {
  4171. #else
  4172. else {
  4173. #endif
  4174. s_lstrcpy(lpstmt->szError, scalarFuncs[lpSqlNode->node.scalar.Id].name);
  4175. err = ERR_SCALARBADARG;
  4176. }
  4177. #ifndef WIN32
  4178. /* Turn off exception handler */
  4179. if (func != SIG_ERR)
  4180. signal(SIGFPE, func);
  4181. #endif
  4182. return err;
  4183. }
  4184. /***************************************************************************/