1 24 25 package com.mckoi.database.interpret; 26 27 import com.mckoi.database.*; 28 import java.io.*; 29 import java.util.ArrayList ; 30 import java.util.List ; 31 32 40 41 public class Call extends Statement { 42 43 45 public void prepare() throws DatabaseException { 46 } 47 48 public Table evaluate() throws DatabaseException { 49 50 DatabaseQueryContext context = new DatabaseQueryContext(database); 51 52 String proc_name = (String ) cmd.getObject("proc_name"); 53 Expression[] args = (Expression[]) cmd.getObject("args"); 54 55 ProcedureManager manager = database.getProcedureManager(); 57 ProcedureName name; 58 59 TableName p_name = null; 60 61 if (proc_name.indexOf(".") == -1) { 64 String schema_name = database.getCurrentSchema(); 66 TableName tp_name = TableName.resolve(Database.SYSTEM_SCHEMA, proc_name); 67 tp_name = database.tryResolveCase(tp_name); 68 69 if (manager.procedureExists(tp_name)) { 71 p_name = tp_name; 72 } 73 } 74 75 if (p_name == null) { 76 String schema_name = database.getCurrentSchema(); 78 TableName tp_name = TableName.resolve(schema_name, proc_name); 79 tp_name = database.tryResolveCase(tp_name); 80 81 boolean ignore_case = database.isInCaseInsensitiveMode(); 83 SchemaDef schema = 84 database.resolveSchemaCase(tp_name.getSchema(), ignore_case); 85 if (schema == null) { 86 throw new DatabaseException("Schema '" + tp_name.getSchema() + 87 "' doesn't exist."); 88 } 89 else { 90 tp_name = new TableName(schema.getName(), tp_name.getName()); 91 } 92 93 if (!manager.procedureExists(tp_name)) { 95 throw new DatabaseException("Stored procedure '" + proc_name + 96 "' was not found."); 97 } 98 99 p_name = tp_name; 100 } 101 102 name = new ProcedureName(p_name); 104 105 if (!database.getDatabase().canUserExecuteStoredProcedure(context, 107 user, name.toString())) { 108 throw new UserAccessException("User not permitted to call: " + proc_name); 109 } 110 111 TObject[] vals = new TObject[args.length]; 113 for (int i = 0; i < args.length; ++i) { 114 if (args[i].isConstant()) { 115 vals[i] = args[i].evaluate(null, null, context); 116 } 117 else { 118 throw new StatementException( 119 "CALL argument is not a constant: " + args[i].text()); 120 } 121 } 122 123 TObject result = manager.invokeProcedure(name, vals); 125 126 return FunctionTable.resultTable(context, result); 128 129 } 130 131 } 132 133 | Popular Tags |