001package gudusoft.gsqlparser;
002
003/**
004 * @deprecated As of v2.0.3.1, please use {@link gudusoft.gsqlparser.sqlenv.TSQLEnv} instead
005 *
006 * In order to link column to table correctly without connecting to database,
007 * we need to provide a class which implements IMetaDatabase to TGSqlParser.
008 * this class tells TGSqlParser the relation ship between column and table.
009 *
010 * <p>Take this SQL for example:
011 * <pre>
012 * SELECT Quantity,b.Time,c.Description
013 * FROM
014 * (SELECT ID2,Time FROM bTab) b
015 * INNER JOIN aTab a on a.ID=b.ID
016 * INNER JOIN cTab c on a.ID=c.ID
017 * </pre>
018 *
019 * <p>General SQL Parser can build relationship between column: ID2 and table: bTable
020 * correctly without metadata information from database because there is only one table
021 * in from clause. But it can't judge column: Quantity belong to table: aTab or cTab,
022 * since no table alias was prefixed to column: Quantity. If no metadata provided,
023 * General SQL Parser will link column: Quantity to the first valid table (here it is aTab)
024 *
025 * <p>If we create a class  metaDB implements IMetaDatabase,then
026 *  TGSqlParser.setMetaDatabase(new metaDB()), General SQL Parser can take this advantage to create
027 *  a correct relationship between column and tables. Here is a sample of metaDB, you
028 *  should create your own metaDB class with meta information from database.
029 *
030 * <pre>
031 * public class metaDB implements IMetaDatabase {
032 *
033 *     String columns[][] = {
034 *         {"dbo","aTab","Quantity1"},
035 *         {"dbo","bTab","Quantity2"},
036 *         {"dbo","cTab","Quantity"}
037 *     };
038 *
039 *     public boolean checkColumn(String schema, String table, String column){
040 *        boolean bSchema,bTable,bColumn,bRet = false;
041 *         for (int i=0; i&lt;columns.length;i++){
042 *             if (schema == null){
043 *                 bSchema = true;
044 *             }else{
045 *                 bSchema = columns[i][0].equalsIgnoreCase(schema);
046 *             }
047 *
048 *             if (!bSchema) continue;
049 *
050 *             bTable = columns[i][1].equalsIgnoreCase(table);
051 *             if (!bTable) continue;
052 *
053 *             bColumn = columns[i][2].equalsIgnoreCase(column);
054 *             if (!bColumn) continue;
055 *
056 *             bRet =true;
057 *             break;
058 *
059 *         }
060 *
061 *         return bRet;
062 *     }
063 *
064 * }
065 *</pre>
066 *
067 * <p>After TGSqlParser.setMetaDatabase(new metaDB()), General SQL parser can generate this
068 * result for you:
069 * <pre>
070 * atab.id
071 * btab.id
072 * btab.time
073 * ctab.description
074 * ctab.id
075 * ctab.quantity
076 * </pre>
077 */
078
079public interface IMetaDatabase {
080    /**
081     * Implement this function to link column to table
082     * @param server
083     * @param database
084     * @param schema
085     * @param table
086     * @param column
087     * @return
088     */
089    public boolean checkColumn(String server, String database,String schema, String table, String column);
090}