Package gudusoft.gsqlparser
Interface IMetaDatabase
public interface IMetaDatabase
Deprecated.
-
Method Summary
-
Method Details
-
checkColumn
Deprecated.Implement this function to link column to table- Parameters:
server-database-schema-table-column-- Returns:
-
TSQLEnvinstead In order to link column to table correctly without connecting to database, we need to provide a class which implements IMetaDatabase to TGSqlParser. this class tells TGSqlParser the relation ship between column and table.Take this SQL for example:
General SQL Parser can build relationship between column: ID2 and table: bTable correctly without metadata information from database because there is only one table in from clause. But it can't judge column: Quantity belong to table: aTab or cTab, since no table alias was prefixed to column: Quantity. If no metadata provided, General SQL Parser will link column: Quantity to the first valid table (here it is aTab)
If we create a class metaDB implements IMetaDatabase,then TGSqlParser.setMetaDatabase(new metaDB()), General SQL Parser can take this advantage to create a correct relationship between column and tables. Here is a sample of metaDB, you should create your own metaDB class with meta information from database.
public class metaDB implements IMetaDatabase { String columns[][] = { {"dbo","aTab","Quantity1"}, {"dbo","bTab","Quantity2"}, {"dbo","cTab","Quantity"} }; public boolean checkColumn(String schema, String table, String column){ boolean bSchema,bTable,bColumn,bRet = false; for (int i=0; i<columns.length;i++){ if (schema == null){ bSchema = true; }else{ bSchema = columns[i][0].equalsIgnoreCase(schema); } if (!bSchema) continue; bTable = columns[i][1].equalsIgnoreCase(table); if (!bTable) continue; bColumn = columns[i][2].equalsIgnoreCase(column); if (!bColumn) continue; bRet =true; break; } return bRet; } }After TGSqlParser.setMetaDatabase(new metaDB()), General SQL parser can generate this result for you: