PageRenderTime 48ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/eclipse-dtp-1.10/org.eclipse.datatools.sqltools-DTP_1_10_0_Release_201206131012/plugins/org.eclipse.datatools.sqltools.sqlbuilder/src/org/eclipse/datatools/sqltools/sqlbuilder/expressionbuilder/MySQLFunctionNamesAndSignatures.java

#
Java | 1154 lines | 1098 code | 39 blank | 17 comment | 284 complexity | a65fe00480c874df7a9e7f44b78b2a94 MD5 | raw file
  1. /*******************************************************************************
  2. * Copyright Š 2000, 2007 IBM Corporation and others.
  3. * All rights reserved. This program and the accompanying materials
  4. * are made available under the terms of the Eclipse Public License v1.0
  5. * which is available at
  6. * http://www.eclipse.org/legal/epl-v10.html
  7. *
  8. * Contributors:
  9. * IBM Corporation - initial API and implementation
  10. *******************************************************************************/
  11. package org.eclipse.datatools.sqltools.sqlbuilder.expressionbuilder;
  12. import java.util.Arrays;
  13. import java.util.List;
  14. import org.eclipse.datatools.sqltools.sqlbuilder.Messages;
  15. import org.eclipse.datatools.sqltools.sqlbuilder.model.SQLDomainModel;
  16. import org.eclipse.swt.widgets.Combo;
  17. public class MySQLFunctionNamesAndSignatures
  18. {
  19. public static final String mySQLAll = Messages._UI_FCN_ALL;
  20. public static final String mySQLString = Messages._UI_FCN_STRING;
  21. public static final String mySQLControlFlow = Messages._UI_FCN_CONTROL_FLOW;
  22. public static final String mySQLMath = Messages._UI_FCN_MATH;
  23. public static final String mySQLBit = Messages._UI_FCN_BIT;
  24. public static final String mySQLDateAndTime = Messages._UI_FCN_DATE_TIME;
  25. public static final String mySQLMiscellaneous = Messages._UI_FCN_MISCELLANEOUS;
  26. public static final String mySQLAggregate = Messages._UI_FCN_AGGREGATE;
  27. public static final String mySQLNotSupported = Messages._UI_FCN_NOT_SUPPORTED;
  28. public static String dbUDF = Messages._UI_FCN_UDF;
  29. private static final String allFunctions[] =
  30. {
  31. "ABS",
  32. "ACOS",
  33. "ADDDATE",
  34. "ASCII",
  35. "ASIN",
  36. "ATAN",
  37. "ATAN2",
  38. "AVG",
  39. "BENCHMARK",
  40. "BIN",
  41. "BIT_AND",
  42. "BIT_COUNT",
  43. "BIT_OR",
  44. "CEILING",
  45. "CHAR",
  46. "CHAR_LENGTH",
  47. "CHARACTER_LENGTH",
  48. "COALESCE",
  49. "CONCAT",
  50. "CONCAT_WS",
  51. "CONNECTION_ID",
  52. "CONV",
  53. "COS",
  54. "COT",
  55. "COUNT",
  56. "CURDATE",
  57. "CURRENT_DATE",
  58. "CURRENT_TIME",
  59. "CURRENT_TIMESTAMP",
  60. "CURTIME",
  61. "DATABASE",
  62. "DATE_ADD",
  63. "DATE_FORMAT",
  64. "DATE_SUB",
  65. "DAYNAME",
  66. "DAYOFMONTH",
  67. "DAYOFWEEK",
  68. "DAYOFYEAR",
  69. "DECODE",
  70. "DEGREES",
  71. "ELT",
  72. "ENCODE",
  73. "ENCRYPT",
  74. "EXP",
  75. "EXPORT_SET",
  76. "FIELD",
  77. "FIND_IN_SET",
  78. "FLOOR",
  79. "FORMAT",
  80. "FROM_DAYS",
  81. "FROM_UNIXTIME",
  82. "GET_LOCK",
  83. "GREATEST",
  84. "HEX",
  85. "HOUR",
  86. "IF",
  87. "IFNULL",
  88. "INET_ATON",
  89. "INET_NTOA",
  90. "INSERT",
  91. "INSTR",
  92. "INTERVAL",
  93. "ISNULL",
  94. "LAST_INSERT_ID",
  95. "LCASE",
  96. "LEAST",
  97. "LEFT",
  98. "LENGTH",
  99. "LOAD_FILE",
  100. "LOCATE",
  101. "LOG",
  102. "LOG10",
  103. "LOWER",
  104. "LPAD",
  105. "LTRIM",
  106. "MAKE_SET",
  107. "MASTER_POS_WAIT",
  108. // "MATCH ... AGAINST", // not supported now
  109. "MAX",
  110. "MD5",
  111. "MID",
  112. "MIN",
  113. "MINUTE",
  114. "MOD",
  115. "MONTH",
  116. "MONTHNAME",
  117. "NOW",
  118. "NULLIF",
  119. "OCT",
  120. "OCTET_LENGTH",
  121. "ORD",
  122. "PASSWORD",
  123. "PERIOD_ADD",
  124. "PERIOD_DIFF",
  125. "PI",
  126. "POSITION",
  127. "POW",
  128. "POWER",
  129. "QUARTER",
  130. "RADIANS",
  131. "RAND",
  132. "RELEASE_LOCK",
  133. "REPEAT",
  134. "REPLACE",
  135. "REVERSE",
  136. "RIGHT",
  137. "ROUND",
  138. "RPAD",
  139. "RTRIM",
  140. "SEC_TO_TIME",
  141. "SECOND",
  142. "SESSION_USER",
  143. "SIGN",
  144. "SIN",
  145. "SOUNDEX",
  146. "SPACE",
  147. "SQRT",
  148. "STD",
  149. "STDDEV",
  150. "STRCMP",
  151. "SUBDATE",
  152. "SUBSTRING",
  153. "SUBSTRING_INDEX",
  154. "SUM",
  155. "SYSDATE",
  156. "SYSTEM_USER",
  157. "TAN",
  158. "TIME_FORMAT",
  159. "TIME_TO_SEC",
  160. "TO_DAYS",
  161. "TRIM",
  162. "TRUNCATE",
  163. "UCASE",
  164. "UNIX_TIMESTAMP",
  165. "UPPER",
  166. "USER",
  167. "VERSION",
  168. "WEEK",
  169. "WEEKDAY",
  170. "YEAR",
  171. "YEARWEEK"
  172. };
  173. private static final String allColumnSupportedFunctions[] = allFunctions;
  174. private static final String unsupportedFunctions[] =
  175. {
  176. "CHAR",
  177. "COALESCE",
  178. "ELT",
  179. "FIELD",
  180. "GREATEST",
  181. "INTERVAL",
  182. "LEAST",
  183. "MAKE_SET",
  184. "MASTER_POS_WAIT",
  185. // "MATCH ... AGAINST",
  186. "POSITION"
  187. };
  188. private static final String functionsSupportingStar[] =
  189. {
  190. "COUNT"
  191. };
  192. private static final String noBracketFunctions[] =
  193. {
  194. "CURRENT_DATE",
  195. "CURRENT_TIME",
  196. "CURRENT_TIMESTAMP"
  197. };
  198. private static final String bitFunctions[] =
  199. {
  200. "BIT_COUNT"
  201. };
  202. private static final String stringFunctions[] =
  203. {
  204. "ASCII", // ASCII(str)
  205. "BIN", // BIN(N)
  206. "CHAR", // CHAR(N,...)
  207. "CHAR_LENGTH", // CHAR_LENGTH(str)
  208. "CHARACTER_LENGTH", // CHARACTER_LENGTH(str)
  209. "CONCAT", // CONCAT(str1, str2, ...)
  210. "CONCAT_WS", // CONCAT_WS(separator, str1, str2, ...)
  211. "CONV", // CONV(N, from_base, to_base)
  212. "ELT",
  213. "EXPORT_SET",
  214. "FIELD",
  215. "FIND_IN_SET",
  216. "HEX", // HEX(BIGINT)
  217. "INSERT",
  218. "INSTR", // INSTR(str, substr)
  219. "LCASE",
  220. "LEFT", // LEFT(str, len)
  221. "LENGTH", // LENGTH(str)
  222. "LOAD_FILE",
  223. "LOCATE", // LOCATE(substr, str) LOCATE(substr, str, pos)
  224. "LOWER",
  225. "LPAD", // LPAD(str,len,padstr)
  226. "LTRIM",
  227. "MAKE_SET",
  228. //"MATCH ... AGAINST", // not supported now
  229. "MID", // MID(str, pos, len)
  230. "OCT", // OCT(longlong)
  231. "OCTET_LENGTH", // OCTET_LENGTH(str)
  232. "ORD", // ORD(str)
  233. "POSITION", // POSITION(substr IN str)
  234. "REPEAT",
  235. "REPLACE",
  236. "REVERSE",
  237. "RIGHT", // RIGHT(str, len)
  238. "RPAD", // RPAD(str, len, padstr)
  239. "RTRIM",
  240. "SOUNDEX",
  241. "SPACE",
  242. "STRCMP",
  243. "SUBSTRING",
  244. "SUBSTRING_INDEX",
  245. "TRIM",
  246. "UCASE",
  247. "UPPER"
  248. };
  249. private static final String controlFlowFunctions[] =
  250. {
  251. "IF",
  252. "IFNULL",
  253. "NULLIF"
  254. };
  255. private static final String mathFunctions[] =
  256. {
  257. "ABS",
  258. "ACOS",
  259. "ASIN",
  260. "ATAN",
  261. "ATAN2",
  262. "CEILING",
  263. "COS",
  264. "COT",
  265. "DEGREES",
  266. "EXP",
  267. "FLOOR",
  268. "GREATEST",
  269. "LEAST",
  270. "LOG",
  271. "LOG10",
  272. "MOD",
  273. "PI",
  274. "POW",
  275. "POWER",
  276. "RADIANS",
  277. "RAND",
  278. "ROUND",
  279. "SIGN",
  280. "SIN",
  281. "SQRT",
  282. "TAN",
  283. "TRUNCATE"
  284. };
  285. private static final String dateAndTimeFunctions[] =
  286. {
  287. "ADDDATE",
  288. "CURDATE",
  289. "CURRENT_DATE",
  290. "CURRENT_TIME",
  291. "CURRENT_TIMESTAMP",
  292. "CURTIME",
  293. "DATE_ADD",
  294. "DATE_FORMAT",
  295. "DATE_SUB",
  296. "DAYNAME",
  297. "DAYOFMONTH",
  298. "DAYOFWEEK",
  299. "DAYOFYEAR",
  300. "FROM_DAYS",
  301. "FROM_UNIXTIME",
  302. "HOUR",
  303. "MINUTE",
  304. "MONTH",
  305. "MONTHNAME",
  306. "NOW",
  307. "PERIOD_ADD",
  308. "PERIOD_DIFF",
  309. "QUARTER",
  310. "SEC_TO_TIME",
  311. "SECOND",
  312. "SUBDATE",
  313. "SYSDATE",
  314. "TIME_FORMAT",
  315. "TIME_TO_SEC",
  316. "TO_DAYS",
  317. "UNIX_TIMESTAMP",
  318. "WEEK",
  319. "WEEKDAY",
  320. "YEAR",
  321. "YEARWEEK"
  322. };
  323. private static final String miscFunctions[] =
  324. {
  325. "BENCHMARK",
  326. "COALESCE",
  327. "CONNECTION_ID",
  328. "DATABASE",
  329. "DECODE",
  330. "ENCODE",
  331. "ENCRYPT",
  332. "FORMAT",
  333. "GET_LOCK",
  334. "INET_ATON",
  335. "INET_NTOA",
  336. "INTERVAL",
  337. "ISNULL",
  338. "LAST_INSERT_ID",
  339. "MASTER_POS_WAIT",
  340. "MD5",
  341. "PASSWORD",
  342. "RELEASE_LOCK",
  343. "SESSION_USER",
  344. "SYSTEM_USER",
  345. "USER",
  346. "VERSION"
  347. };
  348. private static final String aggregateFunctions[] =
  349. {
  350. "AVG",
  351. "BIT_AND",
  352. "BIT_OR",
  353. "COUNT",
  354. "MAX",
  355. "MIN",
  356. "STD",
  357. "STDDEV",
  358. "SUM"
  359. };
  360. public static Object[][] getParms(String func)
  361. {
  362. Object[][] list = new Object[1][2];
  363. list[0][0] = "???"; list[0][1] = "???";
  364. if (func.equals("ABS"))
  365. {
  366. list[0][0] = "numeric_expression"; list[0][1] = "numeric_expression";
  367. }
  368. else if (func.equals("ACOS"))
  369. {
  370. list[0][0] = "numeric_expression"; list[0][1] = "numeric_expression";
  371. }
  372. else if (func.equals("ADDDATE"))
  373. {
  374. list[0][0] = "date"; list[0][1] = "INTERVAL expr type";
  375. }
  376. else if (func.equals("ASCII"))
  377. {
  378. list = new Object[2][2];
  379. list[0][0] = "integer"; list[0][1] = "string";
  380. list[1][0] = "integer"; list[1][1] = "string";
  381. }
  382. else if (func.equals("ASIN"))
  383. {
  384. list[0][0] = "numeric_expression"; list[0][1] = "numeric_expression";
  385. }
  386. else if (func.equals("ATAN"))
  387. {
  388. list[0][0] = "numeric_expression"; list[0][1] = "numeric_expression";
  389. }
  390. else if (func.equals("ATAN2"))
  391. {
  392. list = new Object[1][3];
  393. list[0][0] = "numeric_expression"; list[0][1] = "numeric_expression"; list[0][2] = "numeric_expression";
  394. }
  395. else if (func.equals("AVG")) // DISTINCT, ALL
  396. {
  397. list[0][0] = "numeric_expression"; list[0][1] = "expression";
  398. }
  399. else if (func.equals("BENCHMARK"))
  400. {
  401. list = new Object[1][3];
  402. list[0][0] = "0"; list[0][1] = "numeric_expression"; list[0][2] = "expression";
  403. }
  404. else if (func.equals("BIN"))
  405. {
  406. list[0][0] = "string"; list[0][1] = "BIGINT";
  407. }
  408. else if (func.equals("BIT_AND"))
  409. {
  410. list[0][0] = "expression"; list[0][1] = "expression";
  411. }
  412. else if (func.equals("BIT_COUNT"))
  413. {
  414. list[0][0] = "integer"; list[0][1] = "expression";
  415. }
  416. else if (func.equals("BIT_OR"))
  417. {
  418. list[0][0] = "expression"; list[0][1] = "expression";
  419. }
  420. else if (func.equals("CEILING"))
  421. {
  422. list[0][0] = "integer"; list[0][1] = "numeric_expression";
  423. }
  424. else if (func.equals("CHAR")) // signature is char(N,...)
  425. {
  426. list = new Object[1][1];
  427. list[0][0] = mySQLNotSupported;
  428. // list[0][0] = "character"; list[0][1] = "integer";
  429. }
  430. else if (func.equals("CHAR_LENGTH") ||
  431. func.equals("CHARACTER_LENGTH") ||
  432. func.equals("LENGTH") ||
  433. func.equals("OCTET_LENGTH"))
  434. {
  435. list[0][0] = "integer"; list[0][1] = "char_expression";
  436. }
  437. else if (func.equals("COALESCE"))
  438. {
  439. list = new Object[1][1];
  440. list[0][0] = mySQLNotSupported;
  441. }
  442. else if (func.equals("CONCAT")) // signature is CONCAT(str1, str2, ...)
  443. {
  444. list = new Object[1][3];
  445. list[0][0] = "string"; list[0][1] = "string"; list[0][2] = "string";
  446. }
  447. else if (func.equals("CONCAT_WS")) // signature is CONCAT(separator, str1, str2, ...)
  448. {
  449. list = new Object[1][4];
  450. list[0][0] = "string"; list[0][1] = "separator string"; list[0][2] = "string"; list[0][3] = "string";
  451. }
  452. else if (func.equals("CONNECTION_ID"))
  453. {
  454. list = new Object[1][1];
  455. list[0][0] = "integer";
  456. }
  457. else if (func.equals("CONV"))
  458. {
  459. list = new Object[2][4];
  460. list[0][0] = "string"; list[0][1] = "integer"; list[0][2] = "from_base"; list[0][3] = "to_base";
  461. list[1][0] = "string"; list[1][1] = "string"; list[1][2] = "from_base"; list[1][3] = "to_base";
  462. }
  463. else if (func.equals("COS"))
  464. {
  465. list[0][0] = "numeric_expression"; list[0][1] = "numeric_expression";
  466. }
  467. else if (func.equals("COT"))
  468. {
  469. list[0][0] = "numeric_expression"; list[0][1] = "numeric_expression";
  470. }
  471. else if (func.equals("COUNT")) // DISTINCT, ALL
  472. {
  473. list[0][0] = "numeric_expression"; list[0][1] = "expression";
  474. }
  475. else if (func.equals("CURDATE") ||
  476. func.equals("CURRENT_DATE"))
  477. {
  478. list = new Object[1][1];
  479. list[0][0] = "date";
  480. }
  481. else if (func.equals("CURRENT_TIME") ||
  482. func.equals("CURTIME"))
  483. {
  484. list = new Object[1][1];
  485. list[0][0] = "time";
  486. }
  487. else if (func.equals("CURRENT_TIMESTAMP"))
  488. {
  489. list = new Object[1][1];
  490. list[0][0] = "date and time";
  491. }
  492. else if (func.equals("DATABASE"))
  493. {
  494. list = new Object[1][1];
  495. list[0][0] = "database name (string)";
  496. }
  497. else if (func.equals("DATE_ADD"))
  498. {
  499. list[0][0] = "date"; list[0][1] = "INTERVAL expr type";
  500. }
  501. else if (func.equals("DATE_FORMAT"))
  502. {
  503. list = new Object[1][3];
  504. list[0][0] = "date"; list[0][1] = "date"; list[0][2] = "format string";
  505. }
  506. else if (func.equals("DATE_SUB"))
  507. {
  508. list[0][0] = "date"; list[0][1] = "INTERVAL expr type";
  509. }
  510. else if (func.equals("DAYNAME"))
  511. {
  512. list[0][0] = "string"; list[0][1] = "date";
  513. }
  514. else if (func.equals("DAYOFMONTH"))
  515. {
  516. list[0][0] = "decimal"; list[0][1] = "date";
  517. }
  518. else if (func.equals("DAYOFWEEK"))
  519. {
  520. list[0][0] = "decimal"; list[0][1] = "date";
  521. }
  522. else if (func.equals("DAYOFYEAR"))
  523. {
  524. list[0][0] = "decimal"; list[0][1] = "date";
  525. }
  526. else if (func.equals("DECODE"))
  527. {
  528. list = new Object[1][3];
  529. list[0][0] = "string"; list[0][1] = "crypt_str"; list[0][2] = "pass_string";
  530. }
  531. else if (func.equals("DEGREES"))
  532. {
  533. list[0][0] = "numeric_expression"; list[0][1] = "nuneric_expression";
  534. }
  535. else if (func.equals("ELT")) // signature is ELT(N, str1, str2, str3,...)
  536. {
  537. list = new Object[1][1];
  538. list[0][0] = mySQLNotSupported;
  539. }
  540. else if (func.equals("ENCODE"))
  541. {
  542. list = new Object[1][3];
  543. list[0][0] = "binary string"; list[0][1] = "string"; list[0][2] = "pass_string";
  544. }
  545. else if (func.equals("ENCRYPT"))
  546. {
  547. list = new Object[2][];
  548. list[0] = new Object[2];
  549. list[1] = new Object[3];
  550. list[0][0] = "string"; list[0][1] = "string";
  551. list[1][0] = "string"; list[1][1] = "string"; list[1][2] = "string";
  552. }
  553. else if (func.equals("EXP")) // float, real, or double precision
  554. {
  555. list[0][0] = "numeric_expression"; list[0][1] = "numeric_expression";
  556. }
  557. else if (func.equals("EXPORT_SET"))
  558. {
  559. list = new Object[3][];
  560. list[0] = new Object[4];
  561. list[1] = new Object[5];
  562. list[2] = new Object[6];
  563. list[0][0] = "string"; list[0][1] = "bits"; list[0][2] = "on string"; list[0][3] = "off string";
  564. list[1][0] = "string"; list[1][1] = "bits"; list[1][2] = "on string"; list[1][3] = "off string"; list[1][4] = "separator string";
  565. list[2][0] = "string"; list[2][1] = "bits"; list[2][2] = "on string"; list[2][3] = "off string"; list[2][4] = "separator string"; list[2][5] = "number_of_bits";
  566. }
  567. else if (func.equals("FIELD")) // signature is FIELD(str,str1,str2,str3,...)
  568. {
  569. list = new Object[1][1];
  570. list[0][0] = mySQLNotSupported;
  571. }
  572. else if (func.equals("FIND_IN_SET"))
  573. {
  574. list = new Object[1][3];
  575. list[0][0] = "integer"; list[0][1] = "string"; list[0][2] = "string";
  576. }
  577. else if (func.equals("FLOOR"))
  578. {
  579. list[0][0] = "integer"; list[0][1] = "numeric_expression";
  580. }
  581. else if (func.equals("FORMAT"))
  582. {
  583. list = new Object[1][3];
  584. list[0][0] = "numeric_expression"; list[0][1] = "numeric_expression"; list[0][2] = "integer";
  585. }
  586. else if (func.equals("FROM_DAYS"))
  587. {
  588. list[0][0] = "date"; list[0][1] = "numeric_expression";
  589. }
  590. else if (func.equals("FROM_UNIXTIME"))
  591. {
  592. list = new Object[4][];
  593. list[0] = new Object[2];
  594. list[1] = new Object[2];
  595. list[2] = new Object[3];
  596. list[3] = new Object[3];
  597. list[0][0] = "string"; list[0][1] = "unix_timestamp";
  598. list[1][0] = "numeric"; list[1][1] = "unix_timestamp";
  599. list[2][0] = "string"; list[2][1] = "unix_timestamp"; list[2][2] = "format";
  600. list[3][0] = "numeric"; list[3][1] = "unix_timestamp"; list[3][2] = "format";
  601. }
  602. else if (func.equals("GET_LOCK"))
  603. {
  604. list = new Object[1][3];
  605. list[0][0] = "integer"; list[0][1] = "string"; list[0][2] = "timeout";
  606. }
  607. else if (func.equals("GREATEST"))
  608. {
  609. list = new Object[1][1];
  610. list[0][0] = mySQLNotSupported;
  611. // list[0][0] = "expression"; list[0][1] = "expression";
  612. }
  613. else if (func.equals("HEX"))
  614. {
  615. list[0][0] = "string"; list[0][1] = "BIGINT";
  616. }
  617. else if (func.equals("HOUR"))
  618. {
  619. list[0][0] = "string"; list[0][1] = "TIME";
  620. }
  621. else if (func.equals("IF"))
  622. {
  623. list = new Object[1][4];
  624. list[0][0] = "expression"; list[0][1] = "expression"; list[0][2] = "expression"; list[0][3] = "expression";
  625. }
  626. else if (func.equals("IFNULL"))
  627. {
  628. list = new Object[1][3];
  629. list[0][0] = "expression"; list[0][1] = "expression"; list[0][2] = "expression";
  630. }
  631. else if (func.equals("INET_ATON"))
  632. {
  633. list[0][0] = "numeric_expression"; list[0][1] = "expression";
  634. }
  635. else if (func.equals("INET_NTOA"))
  636. {
  637. list[0][0] = "expression"; list[0][1] = "numeric_expression";
  638. }
  639. else if (func.equals("INSERT"))
  640. {
  641. list = new Object[1][5];
  642. list[0][0] = "string"; list[0][1] = "string"; list[0][2] = "pos"; list[0][3] = "len"; list[0][4] = "string";
  643. }
  644. else if (func.equals("INSTR"))
  645. {
  646. list = new Object[1][3];
  647. list[0][0] = "integer"; list[0][1] = "string"; list[0][2] = "substr";
  648. }
  649. else if (func.equals("INTERVAL")) // Signature is INTERVAL(N,N1,N2,N3,...)
  650. {
  651. list = new Object[1][1];
  652. list[0][0] = mySQLNotSupported;
  653. }
  654. else if (func.equals("ISNULL"))
  655. {
  656. list[0][0] = "integer"; list[0][1] = "expression";
  657. }
  658. else if (func.equals("LAST_INSERT_ID"))
  659. {
  660. list = new Object[2][];
  661. list[0] = new Object[1];
  662. list[1] = new Object[2];
  663. list[0][0] = "expression";
  664. list[1][0] = "expression"; list[1][1] = "expression";
  665. }
  666. else if (func.equals("LCASE") ||
  667. func.equals("LOWER"))
  668. {
  669. list[0][0] = "string"; list[0][1] = "string";
  670. }
  671. else if (func.equals("LEAST")) // Signature is LEAST(X,Y,...)
  672. {
  673. list = new Object[1][1];
  674. list[0][0] = mySQLNotSupported;
  675. // list[0][0] = "expression"; list[0][1] = "expression";
  676. }
  677. else if (func.equals("LEFT"))
  678. {
  679. list = new Object[1][3];
  680. list[0][0] = "string"; list[0][1] = "string"; list[0][2] = "len";
  681. }
  682. else if (func.equals("LOAD_FILE"))
  683. {
  684. list[0][0] = "string"; list[0][1] = "file_name (string)";
  685. }
  686. else if (func.equals("LOCATE"))
  687. {
  688. list = new Object[2][];
  689. list[0] = new Object[3];
  690. list[1] = new Object[4];
  691. list[0][0] = "integer"; list[0][1] = "substr"; list[0][2] = "string";
  692. list[1][0] = "integer"; list[1][1] = "substr"; list[1][2] = "string"; list[1][3] = "pos";
  693. }
  694. else if (func.equals("LOG"))
  695. {
  696. list[0][0] = "numeric_expression"; list[0][1] = "numeric_expression";
  697. }
  698. else if (func.equals("LOG10"))
  699. {
  700. list[0][0] = "numeric_expression"; list[0][1] = "numeric_expression";
  701. }
  702. else if (func.equals("LPAD"))
  703. {
  704. list = new Object[1][4];
  705. list[0][0] = "string"; list[0][1] = "string"; list[0][2] = "len"; list[0][3] = "padstring";
  706. }
  707. else if (func.equals("LTRIM"))
  708. {
  709. list[0][0] = "string"; list[0][1] = "string";
  710. }
  711. else if (func.equals("MAKE_SET")) // Signature is MAKE_SET(bits,str1,str2,...)
  712. {
  713. list = new Object[1][1];
  714. list[0][0] = mySQLNotSupported;
  715. }
  716. else if (func.equals("MASTER_POS_WAIT"))
  717. {
  718. list = new Object[1][1];
  719. list[0][0] = mySQLNotSupported;
  720. }
  721. else if (func.equals("MAX"))
  722. {
  723. list[0][0] = "expression"; list[0][1] = "expression";
  724. }
  725. else if (func.equals("MD5"))
  726. {
  727. list[0][0] = "hexadecimal"; list[0][1] = "string";
  728. }
  729. else if (func.equals("MID"))
  730. {
  731. list = new Object[1][4];
  732. list[0][0] = "string"; list[0][1] = "string"; list[0][2] = "pos"; list[0][3] = "len";
  733. }
  734. else if (func.equals("MIN"))
  735. {
  736. list[0][0] = "expression"; list[0][1] = "expression";
  737. }
  738. else if (func.equals("MINUTE"))
  739. {
  740. list[0][0] = "decimal"; list[0][1] = "time";
  741. }
  742. else if (func.equals("MOD"))
  743. {
  744. list = new Object[1][3];
  745. list[0][0] = "numeric"; list[0][1] = "numeric"; list[0][2] = "numeric";
  746. }
  747. else if (func.equals("MONTH"))
  748. {
  749. list[0][0] = "integer"; list[0][1] = "date";
  750. }
  751. else if (func.equals("MONTHNAME"))
  752. {
  753. list[0][0] = "string"; list[0][1] = "date";
  754. }
  755. else if (func.equals("NOW"))
  756. {
  757. list = new Object[1][1];
  758. list[0][0] = "date and time";
  759. }
  760. else if (func.equals("NULLIF"))
  761. {
  762. list = new Object[1][3];
  763. list[0][0] = "expression"; list[0][1] = "expression"; list[0][2] = "expression";
  764. }
  765. else if (func.equals("OCT"))
  766. {
  767. list[0][0] = "string"; list[0][1] = "longlong";
  768. }
  769. else if (func.equals("ORD"))
  770. {
  771. list[0][0] = "ASCII code"; list[0][1] = "string";
  772. }
  773. else if (func.equals("PASSWORD"))
  774. {
  775. list[0][0] = "string"; list[0][1] = "string";
  776. }
  777. else if (func.equals("PERIOD_ADD"))
  778. {
  779. list = new Object[1][3];
  780. list[0][0] = "YYYYMM (numeric)"; list[0][1] = "YYMM | YYYYMM (numeric)"; list[0][2] = "integer";
  781. }
  782. else if (func.equals("PERIOD_DIFF"))
  783. {
  784. list = new Object[1][3];
  785. list[0][0] = "decimal"; list[0][1] = "YYMM | YYYYMM (numeric)"; list[0][2] = "YYMM | YYYYMM (numeric)";
  786. }
  787. else if (func.equals("PI"))
  788. {
  789. list = new Object[1][1];
  790. list[0][0] = "numeric";
  791. }
  792. else if (func.equals("POSITION"))
  793. {
  794. list = new Object[1][1];
  795. list[0][0] = mySQLNotSupported;
  796. }
  797. else if (func.equals("POW") ||
  798. func.equals("POWER"))
  799. {
  800. list = new Object[1][3];
  801. list[0][0] = "numeric"; list[0][1] = "value"; list[0][2] = "power";
  802. }
  803. else if (func.equals("QUARTER"))
  804. {
  805. list[0][0] = "decimal"; list[0][1] = "date";
  806. }
  807. else if (func.equals("RADIANS"))
  808. {
  809. list[0][0] = "numeric_expression"; list[0][1] = "numeric_expression";
  810. }
  811. else if (func.equals("RAND"))
  812. {
  813. list = new Object[2][];
  814. list[0] = new Object[1];
  815. list[1] = new Object[2];
  816. list[0][0] = "numeric";
  817. list[1][0] = "numeric"; list[1][1] = "integer";
  818. }
  819. else if (func.equals("RELEASE_LOCK"))
  820. {
  821. list[0][0] = "integer"; list[0][1] = "string";
  822. }
  823. else if (func.equals("REPEAT"))
  824. {
  825. list = new Object[1][3];
  826. list[0][0] = "string"; list[0][1] = "string"; list[0][2] = "integer";
  827. }
  828. else if (func.equals("REPLACE"))
  829. {
  830. list = new Object[1][4];
  831. list[0][0] = "string"; list[0][1] = "string"; list[0][2] = "from_string"; list[0][3] = "to_string";
  832. }
  833. else if (func.equals("REVERSE"))
  834. {
  835. list[0][0] = "string"; list[0][1] = "string";
  836. }
  837. else if (func.equals("RIGHT"))
  838. {
  839. list = new Object[1][3];
  840. list[0][0] = "string"; list[0][1] = "string"; list[0][2] = "length";
  841. }
  842. else if (func.equals("ROUND"))
  843. {
  844. list = new Object[2][];
  845. list[0] = new Object[2];
  846. list[1] = new Object[3];
  847. list[0][0] = "integer"; list[0][1] = "numeric";
  848. list[1][0] = "numeric"; list[1][1] = "numeric"; list[1][2] = "decimal";
  849. }
  850. else if (func.equals("RPAD"))
  851. {
  852. list = new Object[1][4];
  853. list[0][0] = "string"; list[0][1] = "string"; list[0][2] = "len"; list[0][3] = "padstring";
  854. }
  855. else if (func.equals("RTRIM"))
  856. {
  857. list[0][0] = "string"; list[0][1] = "string";
  858. }
  859. else if (func.equals("SEC_TO_TIME"))
  860. {
  861. list[0][0] = "time"; list[0][1] = "numeric";
  862. }
  863. else if (func.equals("SECOND"))
  864. {
  865. list[0][0] = "decimal"; list[0][1] = "time";
  866. }
  867. else if (func.equals("SESSION_USER"))
  868. {
  869. list = new Object[1][1];
  870. list[0][0] = "string";
  871. }
  872. else if (func.equals("SIGN"))
  873. {
  874. list[0][0] = "sign (integer)"; list[0][1] = "numeric_expression";
  875. }
  876. else if (func.equals("SIN"))
  877. {
  878. list[0][0] = "numeric_expression"; list[0][1] = "numeric_expression";
  879. }
  880. else if (func.equals("SOUNDEX"))
  881. {
  882. list[0][0] = "string"; list[0][1] = "string";
  883. }
  884. else if (func.equals("SPACE"))
  885. {
  886. list[0][0] = "string"; list[0][1] = "integer";
  887. }
  888. else if (func.equals("SQRT"))
  889. {
  890. list[0][0] = "numeric_expression"; list[0][1] = "numeric_expression";
  891. }
  892. else if (func.equals("STD") ||
  893. func.equals("STDDEV"))
  894. {
  895. list[0][0] = "expression"; list[0][1] = "expression";
  896. }
  897. else if (func.equals("STRCMP"))
  898. {
  899. list = new Object[1][3];
  900. list[0][0] = "integer"; list[0][1] = "string"; list[0][2] = "string";
  901. }
  902. else if (func.equals("SUBDATE"))
  903. {
  904. list[0][0] = "date"; list[0][1] = "INTERVAL expr type";
  905. }
  906. else if (func.equals("SUBSTRING"))
  907. {
  908. list = new Object[2][];
  909. list[0] = new Object[3];
  910. list[1] = new Object[4];
  911. list[0][0] = "string"; list[0][1] = "string"; list[0][2] = "pos";
  912. list[1][0] = "string"; list[1][1] = "string"; list[1][2] = "pos"; list[1][3] = "len";
  913. }
  914. else if (func.equals("SUBSTRING_INDEX"))
  915. {
  916. list = new Object[1][4];
  917. list[0][0] = "string"; list[0][1] = "string"; list[0][2] = "delim"; list[0][3] = "count";
  918. }
  919. else if (func.equals("SUM")) // DISTINCT | ALL
  920. {
  921. list[0][0] = "expression"; list[0][1] = "expression";
  922. }
  923. else if (func.equals("SYSDATE"))
  924. {
  925. list = new Object[1][1];
  926. list[0][0] = "date and time";
  927. }
  928. else if (func.equals("SYSTEM_USER"))
  929. {
  930. list = new Object[1][1];
  931. list[0][0] = "string";
  932. }
  933. else if (func.equals("TAN"))
  934. {
  935. list[0][0] = "numeric_expression"; list[0][1] = "numeric_expression";
  936. }
  937. else if (func.equals("TIME_FORMAT"))
  938. {
  939. list = new Object[1][3];
  940. list[0][0] = "time"; list[0][1] = "time"; list[0][2] = "format";
  941. }
  942. else if (func.equals("TIME_TO_SEC"))
  943. {
  944. list[0][0] = "decimal"; list[0][1] = "time";
  945. }
  946. else if (func.equals("TO_DAYS"))
  947. {
  948. list[0][0] = "decimal"; list[0][1] = "date";
  949. }
  950. else if (func.equals("TRIM")) // signature is TRIM([[BOTH | LEADING | TRAILING] [remstr] FROM] str)
  951. {
  952. list[0][0] = "string"; list[0][1] = "string";
  953. }
  954. else if (func.equals("TRUNCATE"))
  955. {
  956. list = new Object[1][3];
  957. list[0][0] = "numeric"; list[0][1] = "numeric"; list[0][2] = "decimal";
  958. }
  959. else if (func.equals("UCASE") ||
  960. func.equals("UPPER"))
  961. {
  962. list[0][0] = "string"; list[0][1] = "string";
  963. }
  964. else if (func.equals("UNIX_TIMESTAMP"))
  965. {
  966. list = new Object[2][];
  967. list[0] = new Object[1];
  968. list[1] = new Object[2];
  969. list[0][0] = "decimal";
  970. list[1][0] = "decimal"; list[1][1] = "date";
  971. }
  972. else if (func.equals("USER"))
  973. {
  974. list = new Object[1][1];
  975. list[0][0] = "string";
  976. }
  977. else if (func.equals("VERSION"))
  978. {
  979. list = new Object[1][1];
  980. list[0][0] = "string";
  981. }
  982. else if (func.equals("WEEK"))
  983. {
  984. list = new Object[2][];
  985. list[0] = new Object[2];
  986. list[1] = new Object[3];
  987. list[0][0] = "decimal"; list[0][1] = "date";
  988. list[1][0] = "decimal"; list[1][1] = "date"; list[1][2] = "first (decimal)";
  989. }
  990. else if (func.equals("WEEKDAY"))
  991. {
  992. list[0][0] = "decimal"; list[0][1] = "date";
  993. }
  994. else if (func.equals("YEAR"))
  995. {
  996. list[0][0] = "decimal"; list[0][1] = "date";
  997. }
  998. else if (func.equals("YEARWEEK"))
  999. {
  1000. list = new Object[2][];
  1001. list[0] = new Object[2];
  1002. list[1] = new Object[3];
  1003. list[0][0] = "decimal"; list[0][1] = "date";
  1004. list[1][0] = "decimal"; list[1][1] = "date"; list[1][2] = "first (decimal)";
  1005. }
  1006. else
  1007. {
  1008. list = UDFNamesAndSignatures.getUDFParams(func);
  1009. }
  1010. return list;
  1011. } // end getParms
  1012. public static Object[][] getParameterFormats(String functionName)
  1013. {
  1014. return getParms(functionName);
  1015. }
  1016. public static void fillCategoryCombo(Combo functionsCategoryCombo, boolean isColumn)
  1017. {
  1018. if (!isColumn)
  1019. {
  1020. functionsCategoryCombo.add(mySQLAll);
  1021. functionsCategoryCombo.add(mySQLAggregate);
  1022. functionsCategoryCombo.add(mySQLBit);
  1023. functionsCategoryCombo.add(mySQLControlFlow);
  1024. functionsCategoryCombo.add(mySQLDateAndTime);
  1025. functionsCategoryCombo.add(mySQLMath);
  1026. functionsCategoryCombo.add(mySQLMiscellaneous);
  1027. functionsCategoryCombo.add(mySQLString);
  1028. functionsCategoryCombo.add(dbUDF);
  1029. }
  1030. else // need to filter out the valid. For now, allow all.
  1031. {
  1032. functionsCategoryCombo.add(mySQLAll);
  1033. functionsCategoryCombo.add(mySQLAggregate);
  1034. functionsCategoryCombo.add(mySQLBit);
  1035. functionsCategoryCombo.add(mySQLControlFlow);
  1036. functionsCategoryCombo.add(mySQLDateAndTime);
  1037. functionsCategoryCombo.add(mySQLMath);
  1038. functionsCategoryCombo.add(mySQLMiscellaneous);
  1039. functionsCategoryCombo.add(mySQLString);
  1040. functionsCategoryCombo.add(dbUDF);
  1041. }
  1042. }
  1043. // Set up superclass for the various vendor function names and signatures
  1044. public static boolean isFunctionSupportingStar(String s)
  1045. {
  1046. List funcList = Arrays.asList(functionsSupportingStar);
  1047. if (funcList.contains(s))
  1048. {
  1049. return true;
  1050. }
  1051. return false;
  1052. }
  1053. public static boolean isNotSupported(String functionName)
  1054. {
  1055. List funcList = Arrays.asList(unsupportedFunctions);
  1056. if (funcList.contains(functionName))
  1057. {
  1058. return true;
  1059. }
  1060. return false;
  1061. }
  1062. public static boolean requiresNoBrackets(String functionName)
  1063. {
  1064. List funcList = Arrays.asList(noBracketFunctions);
  1065. if (funcList.contains(functionName))
  1066. {
  1067. return true;
  1068. }
  1069. return false;
  1070. }
  1071. public static String[] getFunctionList(String category, boolean isColumn, SQLDomainModel domainModel)
  1072. {
  1073. if (category.equals(mySQLAll))
  1074. {
  1075. if (!isColumn)
  1076. {
  1077. return UDFNamesAndSignatures.mergeTwoArrays(allFunctions,UDFNamesAndSignatures.getUDFNames(domainModel)) ;
  1078. }
  1079. return UDFNamesAndSignatures.mergeTwoArrays(allColumnSupportedFunctions,UDFNamesAndSignatures.getUDFNames(domainModel)) ;
  1080. }
  1081. else if (category.equals(mySQLBit))
  1082. {
  1083. return bitFunctions;
  1084. }
  1085. else if (category.equals(mySQLString))
  1086. {
  1087. return stringFunctions;
  1088. }
  1089. else if (category.equals(mySQLAggregate))
  1090. {
  1091. return aggregateFunctions;
  1092. }
  1093. else if (category.equals(mySQLMath))
  1094. {
  1095. return mathFunctions;
  1096. }
  1097. else if (category.equals(mySQLDateAndTime))
  1098. {
  1099. return dateAndTimeFunctions;
  1100. }
  1101. else if (category.equals(mySQLMiscellaneous))
  1102. {
  1103. return miscFunctions;
  1104. }
  1105. else if (category.equals(mySQLControlFlow))
  1106. {
  1107. return controlFlowFunctions;
  1108. }
  1109. else if (category.equals(dbUDF))
  1110. {
  1111. return UDFNamesAndSignatures.getUDFNames(domainModel);
  1112. }
  1113. return UDFNamesAndSignatures.mergeTwoArrays(allFunctions,UDFNamesAndSignatures.getUDFNames(domainModel)) ;
  1114. }
  1115. }