sql = {}

function sql.get_keywords()
  local keywords0_set = "absolute action add admin after aggregate alias all allocate alter and any are array as asc assertion at authorization before begin binary bit blob body boolean both breadth by call cascade cascaded case cast catalog char character check class clob close collate collation column commit completion connect connection constraint constraints constructor continue corresponding create cross cube current current_date current_path current_role current_time current_timestamp current_user cursor cycle data date datetime day deallocate dec decimal declare default deferrable deferred delete depth deref desc describe descriptor destroy destructor deterministic dictionary diagnostics disconnect distinct domain double drop dynamic each else end end-exec equals escape every except exception exec execute exists exit external false fetch first float for foreign found from free full function general get global go goto grant group grouping having host hour identity if ignore immediate in indicator initialize initially inner inout input insert int integer intersect interval into is isolation iterate join key language large last lateral leading left less level like limit local localtime localtimestamp locator map match merge minute modifies modify module month names national natural nchar nclob new next no none not null numeric object of off old on only open operation option or order ordinality out outer output package pad parameter parameters partial path postfix precision prefix preorder prepare preserve primary prior privileges procedure public read reads real recursive ref references referencing relative restrict result return returns revoke right role rollback rollup routine row rows savepoint schema scroll scope search second section select sequence session session_user set sets size smallint some| space specific specifictype sql sqlexception sqlstate sqlwarning start state statement static structure system_user table temporary terminate than then time timestamp timezone_hour timezone_minute to trailing transaction translation treat trigger true under union unique unknown unnest update usage user using value values varchar variable varying view when whenever where with without work write year zone"
  return keywords0_set
end

function sql.get_autocomplete()
  local autocomplete_set = "absolute action add admin after aggregate alias all allocate alter and any are array as asc assertion at authorization before begin binary bit blob body boolean both breadth by call cascade cascaded case cast catalog char character check class clob close collate collation column commit completion connect connection constraint constraints constructor continue corresponding create cross cube current current_date current_path current_role current_time current_timestamp current_user cursor cycle data date datetime day deallocate dec decimal declare default deferrable deferred delete depth deref desc describe descriptor destroy destructor deterministic dictionary diagnostics disconnect distinct domain double drop dynamic each else end end-exec equals escape every except exception exec execute exists exit external false fetch first float for foreign found from free full function general get global go goto grant group grouping having host hour identity if ignore immediate in indicator initialize initially inner inout input insert int integer intersect interval into is isolation iterate join key language large last lateral leading left less level like limit local localtime localtimestamp locator map match merge minute modifies modify module month names national natural nchar nclob new next no none not null numeric object of off old on only open operation option or order ordinality out outer output package pad parameter parameters partial path postfix precision prefix preorder prepare preserve primary prior privileges procedure public read reads real recursive ref references referencing relative restrict result return returns revoke right role rollback rollup routine row rows savepoint schema scroll scope search second section select sequence session session_user set sets size smallint some| space specific specifictype sql sqlexception sqlstate sqlwarning start state statement static structure system_user table temporary terminate than then time timestamp timezone_hour timezone_minute to trailing transaction translation treat trigger true under union unique unknown unnest update usage user using value values varchar variable varying view when whenever where with without work write year zone ABSOLUTE ACTION ADD ADMIN AFTER AGGREGATE ALIAS ALL ALLOCATE ALTER AND ANY ARE ARRAY AS ASC ASSERTION AT AUTHORIZATION BEFORE BEGIN BINARY BIT BLOB BODY BOOLEAN BOTH BREADTH BY CALL CASCADE CASCADED CASE CAST CATALOG CHAR CHARACTER CHECK CLASS CLOB CLOSE COLLATE COLLATION COLUMN COMMIT COMPLETION CONNECT CONNECTION CONSTRAINT CONSTRAINTS CONSTRUCTOR CONTINUE CORRESPONDING CREATE CROSS CUBE CURRENT CURRENT_DATE CURRENT_PATH CURRENT_ROLE CURRENT_TIME CURRENT_TIMESTAMP CURRENT_USER CURSOR CYCLE DATA DATE DATETIME DAY DEALLOCATE DEC DECIMAL DECLARE DEFAULT DEFERRABLE DEFERRED DELETE DEPTH DEREF DESC DESCRIBE DESCRIPTOR DESTROY DESTRUCTOR DETERMINISTIC DICTIONARY DIAGNOSTICS DISCONNECT DISTINCT DOMAIN DOUBLE DROP DYNAMIC EACH ELSE END END-EXEC EQUALS ESCAPE EVERY EXCEPT EXCEPTION EXEC EXECUTE EXISTS EXIT EXTERNAL FALSE FETCH FIRST FLOAT FOR FOREIGN FOUND FROM FREE FULL FUNCTION GENERAL GET GLOBAL GO GOTO GRANT GROUP GROUPING HAVING HOST HOUR IDENTITY IF IGNORE IMMEDIATE IN INDICATOR INITIALIZE INITIALLY INNER INOUT INPUT INSERT INT INTEGER INTERSECT INTERVAL INTO IS ISOLATION ITERATE JOIN KEY LANGUAGE LARGE LAST LATERAL LEADING LEFT LESS LEVEL LIKE LIMIT LOCAL LOCALTIME LOCALTIMESTAMP LOCATOR MAP MATCH MERGE MINUTE MODIFIES MODIFY MODULE MONTH NAMES NATIONAL NATURAL NCHAR NCLOB NEW NEXT NO NONE NOT NULL NUMERIC OBJECT OF OFF OLD ON ONLY OPEN OPERATION OPTION OR ORDER ORDINALITY OUT OUTER OUTPUT PACKAGE PAD PARAMETER PARAMETERS PARTIAL PATH POSTFIX PRECISION PREFIX PREORDER PREPARE PRESERVE PRIMARY PRIOR PRIVILEGES PROCEDURE PUBLIC READ READS REAL RECURSIVE REF REFERENCES REFERENCING RELATIVE RESTRICT RESULT RETURN RETURNS REVOKE RIGHT ROLE ROLLBACK ROLLUP ROUTINE ROW ROWS SAVEPOINT SCHEMA SCROLL SCOPE SEARCH SECOND SECTION SELECT SEQUENCE SESSION SESSION_USER SET SETS SIZE SMALLINT SOME| SPACE SPECIFIC SPECIFICTYPE SQL SQLEXCEPTION SQLSTATE SQLWARNING START STATE STATEMENT STATIC STRUCTURE SYSTEM_USER TABLE TEMPORARY TERMINATE THAN THEN TIME TIMESTAMP TIMEZONE_HOUR TIMEZONE_MINUTE TO TRAILING TRANSACTION TRANSLATION TREAT TRIGGER TRUE UNDER UNION UNIQUE UNKNOWN UNNEST UPDATE USAGE USER USING VALUE VALUES VARCHAR VARIABLE VARYING VIEW WHEN WHENEVER WHERE WITH WITHOUT WORK WRITE YEAR ZONE"
  return autocomplete_set
end

function sql.get_calltip()
  local calltip_add =
  {
    "SELECT|SELECT [ ALL | DISTINCT [ ON ( expression [, ...] ) ] ]\\n  [ * | expression [ [ AS ] output_name ] [, ...] ]\\n  [ FROM from_item [, ...] ]\\n  [ WHERE condition ]\\n  [ GROUP BY grouping_element [, ...] ]\\n  [ HAVING condition [, ...] ]\\n  [ ORDER BY expression [ ASC | DESC | USING operator ] [ NULLS { FIRST | LAST } ] [, ...] ]\\n  [ FOR { UPDATE | NO KEY UPDATE | SHARE | KEY SHARE } [ OF table_name [, ...] ] [ NOWAIT ] [...] ]",
    "INSERT|INSERT INTO table_name [ AS alias ] [ ( column_name [, ...] ) ]\\n  VALUES ( { expression | DEFAULT } [, ...] ) [, ...] | query",
    "UPDATE|UPDATE [ ONLY ] table_name [ * ] [ [ AS ] alias ]\\n  SET { column_name = { expression | DEFAULT } |\\n      ( column_name [, ...] ) = { expression | DEFAULT } [, ...] |\\n      ( column_name [, ...] ) = ( sub-SELECT )\\n    } [, ...]\\n  [ FROM from_list ]\\n  [ WHERE condition ]",
    "DELETE|DELETE FROM [ ONLY ] table_name [ * ] [ [ AS ] alias ]\\n  [ WHERE condition | WHERE CURRENT OF cursor_name ]"
  }
  return calltip_add
end

function sql.create_bakup(path)
  local sql_code = {
    "user_sql = {}\n",
    "function user_sql.get_keywords()\n",
    "  local keywords0_set = \"absolute action add admin after aggregate alias all allocate alter and any are array as asc assertion at authorization before begin binary bit blob body boolean both breadth by call cascade cascaded case cast catalog char character check class clob close collate collation column commit completion connect connection constraint constraints constructor continue corresponding create cross cube current current_date current_path current_role current_time current_timestamp current_user cursor cycle data date datetime day deallocate dec decimal declare default deferrable deferred delete depth deref desc describe descriptor destroy destructor deterministic dictionary diagnostics disconnect distinct domain double drop dynamic each else end end-exec equals escape every except exception exec execute exists exit external false fetch first float for foreign found from free full function general get global go goto grant group grouping having host hour identity if ignore immediate in indicator initialize initially inner inout input insert int integer intersect interval into is isolation iterate join key language large last lateral leading left less level like limit local localtime localtimestamp locator map match merge minute modifies modify module month names national natural nchar nclob new next no none not null numeric object of off old on only open operation option or order ordinality out outer output package pad parameter parameters partial path postfix precision prefix preorder prepare preserve primary prior privileges procedure public read reads real recursive ref references referencing relative restrict result return returns revoke right role rollback rollup routine row rows savepoint schema scroll scope search second section select sequence session session_user set sets size smallint some| space specific specifictype sql sqlexception sqlstate sqlwarning start state statement static structure system_user table temporary terminate than then time timestamp timezone_hour timezone_minute to trailing transaction translation treat trigger true under union unique unknown unnest update usage user using value values varchar variable varying view when whenever where with without work write year zone\"\n",
    "  return keywords0_set\n",
    "end\n",
    "\n",
    "function user_sql.get_autocomplete()\n",
    "  local autocomplete_set = \"absolute action add admin after aggregate alias all allocate alter and any are array as asc assertion at authorization before begin binary bit blob body boolean both breadth by call cascade cascaded case cast catalog char character check class clob close collate collation column commit completion connect connection constraint constraints constructor continue corresponding create cross cube current current_date current_path current_role current_time current_timestamp current_user cursor cycle data date datetime day deallocate dec decimal declare default deferrable deferred delete depth deref desc describe descriptor destroy destructor deterministic dictionary diagnostics disconnect distinct domain double drop dynamic each else end end-exec equals escape every except exception exec execute exists exit external false fetch first float for foreign found from free full function general get global go goto grant group grouping having host hour identity if ignore immediate in indicator initialize initially inner inout input insert int integer intersect interval into is isolation iterate join key language large last lateral leading left less level like limit local localtime localtimestamp locator map match merge minute modifies modify module month names national natural nchar nclob new next no none not null numeric object of off old on only open operation option or order ordinality out outer output package pad parameter parameters partial path postfix precision prefix preorder prepare preserve primary prior privileges procedure public read reads real recursive ref references referencing relative restrict result return returns revoke right role rollback rollup routine row rows savepoint schema scroll scope search second section select sequence session session_user set sets size smallint some| space specific specifictype sql sqlexception sqlstate sqlwarning start state statement static structure system_user table temporary terminate than then time timestamp timezone_hour timezone_minute to trailing transaction translation treat trigger true under union unique unknown unnest update usage user using value values varchar variable varying view when whenever where with without work write year zone ABSOLUTE ACTION ADD ADMIN AFTER AGGREGATE ALIAS ALL ALLOCATE ALTER AND ANY ARE ARRAY AS ASC ASSERTION AT AUTHORIZATION BEFORE BEGIN BINARY BIT BLOB BODY BOOLEAN BOTH BREADTH BY CALL CASCADE CASCADED CASE CAST CATALOG CHAR CHARACTER CHECK CLASS CLOB CLOSE COLLATE COLLATION COLUMN COMMIT COMPLETION CONNECT CONNECTION CONSTRAINT CONSTRAINTS CONSTRUCTOR CONTINUE CORRESPONDING CREATE CROSS CUBE CURRENT CURRENT_DATE CURRENT_PATH CURRENT_ROLE CURRENT_TIME CURRENT_TIMESTAMP CURRENT_USER CURSOR CYCLE DATA DATE DATETIME DAY DEALLOCATE DEC DECIMAL DECLARE DEFAULT DEFERRABLE DEFERRED DELETE DEPTH DEREF DESC DESCRIBE DESCRIPTOR DESTROY DESTRUCTOR DETERMINISTIC DICTIONARY DIAGNOSTICS DISCONNECT DISTINCT DOMAIN DOUBLE DROP DYNAMIC EACH ELSE END END-EXEC EQUALS ESCAPE EVERY EXCEPT EXCEPTION EXEC EXECUTE EXISTS EXIT EXTERNAL FALSE FETCH FIRST FLOAT FOR FOREIGN FOUND FROM FREE FULL FUNCTION GENERAL GET GLOBAL GO GOTO GRANT GROUP GROUPING HAVING HOST HOUR IDENTITY IF IGNORE IMMEDIATE IN INDICATOR INITIALIZE INITIALLY INNER INOUT INPUT INSERT INT INTEGER INTERSECT INTERVAL INTO IS ISOLATION ITERATE JOIN KEY LANGUAGE LARGE LAST LATERAL LEADING LEFT LESS LEVEL LIKE LIMIT LOCAL LOCALTIME LOCALTIMESTAMP LOCATOR MAP MATCH MERGE MINUTE MODIFIES MODIFY MODULE MONTH NAMES NATIONAL NATURAL NCHAR NCLOB NEW NEXT NO NONE NOT NULL NUMERIC OBJECT OF OFF OLD ON ONLY OPEN OPERATION OPTION OR ORDER ORDINALITY OUT OUTER OUTPUT PACKAGE PAD PARAMETER PARAMETERS PARTIAL PATH POSTFIX PRECISION PREFIX PREORDER PREPARE PRESERVE PRIMARY PRIOR PRIVILEGES PROCEDURE PUBLIC READ READS REAL RECURSIVE REF REFERENCES REFERENCING RELATIVE RESTRICT RESULT RETURN RETURNS REVOKE RIGHT ROLE ROLLBACK ROLLUP ROUTINE ROW ROWS SAVEPOINT SCHEMA SCROLL SCOPE SEARCH SECOND SECTION SELECT SEQUENCE SESSION SESSION_USER SET SETS SIZE SMALLINT SOME| SPACE SPECIFIC SPECIFICTYPE SQL SQLEXCEPTION SQLSTATE SQLWARNING START STATE STATEMENT STATIC STRUCTURE SYSTEM_USER TABLE TEMPORARY TERMINATE THAN THEN TIME TIMESTAMP TIMEZONE_HOUR TIMEZONE_MINUTE TO TRAILING TRANSACTION TRANSLATION TREAT TRIGGER TRUE UNDER UNION UNIQUE UNKNOWN UNNEST UPDATE USAGE USER USING VALUE VALUES VARCHAR VARIABLE VARYING VIEW WHEN WHENEVER WHERE WITH WITHOUT WORK WRITE YEAR ZONE\"\n",
    "  return autocomplete_set\n",
    "end\n",
    "\n",
    "function user_sql.get_calltip()\n",
    "  local calltip_add =\n",
    "  {\n",
    "    \"SELECT|SELECT [ ALL | DISTINCT [ ON ( expression [, ...] ) ] ]\\\\n  [ * | expression [ [ AS ] output_name ] [, ...] ]\\\\n  [ FROM from_item [, ...] ]\\\\n  [ WHERE condition ]\\\\n  [ GROUP BY grouping_element [, ...] ]\\\\n  [ HAVING condition [, ...] ]\\\\n  [ ORDER BY expression [ ASC | DESC | USING operator ] [ NULLS { FIRST | LAST } ] [, ...] ]\\\\n  [ FOR { UPDATE | NO KEY UPDATE | SHARE | KEY SHARE } [ OF table_name [, ...] ] [ NOWAIT ] [...] ]\",\n",
    "    \"INSERT|INSERT INTO table_name [ AS alias ] [ ( column_name [, ...] ) ]\\\\n  VALUES ( { expression | DEFAULT } [, ...] ) [, ...] | query\",\n",
    "    \"UPDATE|UPDATE [ ONLY ] table_name [ * ] [ [ AS ] alias ]\\\\n  SET { column_name = { expression | DEFAULT } |\\\\n      ( column_name [, ...] ) = { expression | DEFAULT } [, ...] |\\\\n      ( column_name [, ...] ) = ( sub-SELECT )\\\\n    } [, ...]\\\\n  [ FROM from_list ]\\\\n  [ WHERE condition ]\",\n",
    "    \"DELETE|DELETE FROM [ ONLY ] table_name [ * ] [ [ AS ] alias ]\\\\n  [ WHERE condition | WHERE CURRENT OF cursor_name ]\"\n",
    "  }\n",
    "  return calltip_add\n",
    "end\n",
    "return user_sql",
  }
  local shell_code = table.concat(sql_code)
  eu_core.save_file(path, shell_code)
  shell_code = nil
  sql_code = nil
end

return sql