Goal:
To provide my end user with a list of fields to choose from when typing SQL statements.
Within a SELECT statement (both fields clause and FROM clause), the user may use the full table name, or an alias. Which ever method the user enters the table identifier as, I would like them to get a field list, from the appropriate table, that they can choose from, when they press Ctrl-Space.
On my form, I have:
- TSynEdit
- TSynCompletion
The TSynCompletion.Editor is connected to the TSynEdit
I have added some test items. At runtime, I type Ctrl-Space and my list pops up as expected.
I have looked at the example in the SynEdit example folder. There is a subroutine called "Add", which I suspect is to filter the choices. I haven't gotten that far yet.
What is not explained in the example, is, how do I programmatically load the the ItemList of the TSynCompletion, prgrammatically, based on the table name or the alias the user is referring to.
Example SQL:
SELECT FIRST 300 SKIP 0
t1.FIRST_NAME, t1.LAST_NAME, t2.DEPARTMENT
FROM
EMPLOYEE t1
JOIN DEPARTMENT t2 ON t1.DEPT_NO = t2.DEPT_NO
WHERE t1.HIRE_DATE < '1990-JAN-01'
ORDER BY t1.FIRST_NAME
Behavior expected
At any place in the SELECT statement, if the cursor is to the right of "t1." and the user presses Ctrl-Space, the field list of the EMPLOYEE table should appear.
At any place in the SELECT statement, if the cursor is to the right of "EMPLOYEE." and the user presses Ctrl-Space, the field list of the EMPLOYEE table should appear.
At any place in the SELECT statement, if the cursor is to the right of "t2." and the user presses Ctrl-Space, the field list of the DEPARTMENT table should appear.
At any place in the SELECT statement, if the cursor is to the right of "DEPARTMENT." and the user presses Ctrl-Space, the field list of the DEPARTMENT table should appear.
How do I change out the field list accourding to what is to the left of the cursor?
How do I know which table name goes with the alias that the alias characters (followed by a dot) to the left of the cursor refer to?
I know I can extract the field lists for the table name from the Firebird System Tables. I don't need help with that part.
I just need to know which table name I should use to look for the fields, so I can populate the list.
(I'll worry about how the "Add" subroutine works later. I have to load the ItemList somehow first.)