internal virtual void CreateTable() { string query = string.Empty; try { IConnection conn = SQLConnection.GetConnection(); if (DBTableExists()) { if (deleteExisting) { System.Console.Out.WriteLine("deleting table " + tableName); IStatement stmt = conn.CreateStatement(); query = "drop table " + tableName; stmt.Execute(query); stmt.Close(); IStatement stmtindex = conn.CreateStatement(); query = "DROP INDEX IF EXISTS " + tableName + "_index"; stmtindex.Execute(query); stmtindex.Close(); } } System.Console.Out.WriteLine("creating table " + tableName); IStatement stmt_1 = conn.CreateStatement(); //query = "create table IF NOT EXISTS " + tableName + " (\"sentid\" text, \"tokenid\" int, \"patterns\" bytea); "; query = "create table IF NOT EXISTS " + tableName + " (sentid text, patterns bytea); "; stmt_1.Execute(query); stmt_1.Close(); conn.Close(); } catch (SQLException e) { throw new Exception("Error executing query " + query + "\n" + e); } }
//IStatement public void Execute() { bool Condition = false; object obj = condition.Evaluate().GetData(); if (obj is bool) { Condition = (bool)obj; } else { throw new Exception("Not boolen expression in Loop statement"); } LoopStack.Push(); id = LoopStack.Id(); while (Condition) { block.Execute(); if (id > LoopStack.Id()) { break; } Condition = (bool)condition.Evaluate().GetData(); } }
public string Run() { IStatement result = Parse(); result.Execute(); return(ConsoleBuffer.GetBuffer()); }
public override void CreateIndexIfUsingDBAndNotExists() { try { Redwood.Log(Redwood.Dbg, "Creating index for " + tableName); IConnection conn = SQLConnection.GetConnection(); IStatement stmt = conn.CreateStatement(); bool doesnotexist = false; //check if the index already exists try { IStatement stmt2 = conn.CreateStatement(); string query = "SELECT '" + tableName + "_index'::regclass"; stmt2.Execute(query); } catch (SQLException) { doesnotexist = true; } if (doesnotexist) { string indexquery = "create index CONCURRENTLY " + tableName + "_index on " + tableName + " using hash(\"sentid\") "; stmt.Execute(indexquery); Redwood.Log(Redwood.Dbg, "Done creating index for " + tableName); } } catch (SQLException e) { throw new Exception(e); } }
/// <exception cref="Java.Sql.SQLException"/> public virtual void CreateUpsertFunctionPatternIndex() { IConnection conn = SQLConnection.GetConnection(); string s = "CREATE OR REPLACE FUNCTION upsert_patternindex(tablename1 text, index1 bytea) RETURNS VOID AS $$\n" + "DECLARE\n" + "BEGIN\n" + " UPDATE " + patternindicesTable + " SET index = index1 WHERE tablename = tablename1;\n" + " IF NOT FOUND THEN\n" + " INSERT INTO " + patternindicesTable + " values (tablename1, index1);\n" + " END IF;\n" + "END;\n" + "$$ LANGUAGE 'plpgsql';\n"; IStatement st = conn.CreateStatement(); st.Execute(s); conn.Close(); }
public void Execute(IDictionary <string, object> context) { var origPrincipal = Thread.CurrentPrincipal; try { Thread.CurrentPrincipal = Principal(context); Target.Execute(context); } finally { Thread.CurrentPrincipal = origPrincipal; } }
public PrgState OneStep(PrgState state) { IMyStack <IStatement> stack = state.Stack; if (!(stack.IsEmpty())) { IStatement statement = stack.Pop(); return(statement.Execute(state)); } return(null); }
internal EvaluateResult Evaluate(IStatement statement) { try { return(statement.Execute(rte)); } catch (Exception exception) { var message = string.Format(ErrorMessages.RunTimeErrorOccured, exception.Message); throw new RunTimeException(message, exception); } }
public void Execute() { var result = _expression.Eval().AsNumber(); if (Math.Abs(result) > 0.01) { _ifStatement.Execute(); } else { _elseStatement?.Execute(); } }
private ProgramState ExecuteOneStep(ProgramState programState) { MyIStack <IStatement> executionStack = programState.ExecutionStack; if (executionStack.IsEmpty) { throw new InterpreterControllerException("Execution stack is empty!"); } IStatement current = executionStack.Pop(); return(current.Execute(programState)); }
public ProgramState OneStep(ProgramState state) { MyIStack <IStatement> st = state.GetExeStack(); try { IStatement currentStatement = st.Pop(); return(currentStatement.Execute(state)); } catch (EmptyMyStackException) { throw new MyStatementExecutionException("Exception. Execution stack is empty."); } }
public Task <IResult> Execute(IStatement sql) { var deferred = new Deferred <IResult>(); if (_connection == null) { deferred.Reject(new Exception("No active connection")); } else { sql.Execute(_connection, deferred); } return(deferred.Task); }
public void OneStep(ProgramState ps, ExecutionStack es, bool eachExecution) { try { IStatement statement = es.Pop(); statement.Execute(ps); if (eachExecution) { Console.WriteLine(ps.Tostring()); } } catch (CustomException exc) { throw exc; } }
public void Execute(Context.IContext context) { var result = _expression.Interpret(context); if (result.Type == ValueTypes.Bool) { if (TypeHelpers.Convert <bool>(result)) { _statement.Execute(context); } } else { throw new SyntaxException($"If expressions are required to be bool, not {result.Type}"); } }
//pstmt.setInt(2, tokenId); public virtual void CreateUpsertFunction() { try { IConnection conn = SQLConnection.GetConnection(); string s = "CREATE OR REPLACE FUNCTION upsert_patterns(sentid1 text, pats1 bytea) RETURNS VOID AS $$\n" + "DECLARE\n" + "BEGIN\n" + " UPDATE " + tableName + " SET patterns = pats1 WHERE sentid = sentid1;\n" + " IF NOT FOUND THEN\n" + " INSERT INTO " + tableName + " values (sentid1, pats1);\n" + " END IF;\n" + "END;\n" + "$$ LANGUAGE 'plpgsql';\n"; IStatement st = conn.CreateStatement(); st.Execute(s); conn.Close(); } catch (SQLException e) { throw new Exception(e); } }
public void Execute() { for (_init.Execute(); Math.Abs(_termination.Eval().AsNumber()) > 0.01; _increment.Execute()) { try { _statement.Execute(); } catch (BreakStatement bs) { break; } catch (ContinueStatement cs) { continue; } } }
public void Execute() { do { try { _statement.Execute(); } catch (BreakStatement bs) { break; } catch (ContinueStatement cs) { continue; } }while (Math.Abs(_condition.Eval().AsNumber()) > 0.01); }
public static (StringBuilder, StringReader) Execute( this IStatement statement, StringReader stringReader, StringBuilder output, IDictionary <string, object> model = null) { if (statement == null) { throw new ArgumentNullException(nameof(statement)); } if (stringReader == null) { throw new ArgumentNullException(nameof(stringReader)); } var currentLine = stringReader.ReadLine(); return(statement.Execute(currentLine, stringReader, output, model)); }
//Adding google ngrams to the tables for the first time /// <exception cref="Java.Sql.SQLException"/> public static void PopulateTablesInSQL(string dir, ICollection <int> typesOfPhrases) { Connect(); IStatement stmt = connection.CreateStatement(); foreach (int n in typesOfPhrases) { string table = tablenamePrefix + n; if (!ExistsTable(table)) { throw new Exception("Table " + table + " does not exist in the database! Run the following commands in the psql prompt:" + "create table GoogleNgrams_<NGRAM> (phrase text primary key not null, count bigint not null); create index phrase_<NGRAM> on GoogleNgrams_<NGRAM>(phrase);" ); } foreach (string line in IOUtils.ReadLines(new File(dir + "/" + n + "gms/vocab_cs.gz"), typeof(GZIPInputStream))) { string[] tok = line.Split("\t"); string q = "INSERT INTO " + table + " (phrase, count) VALUES (" + EscapeString(tok[0]) + " , " + tok[1] + ");"; stmt.Execute(q); } } }
//IStatement public void Execute() { bool Condition = false; object obj = condition.Evaluate().GetData(); if (obj is bool) { Condition = (bool)obj; } else { throw new Exception("Not boolen expression in if statement"); } if (Condition) { ifstat.Execute(); } else if (elsestat != null) { elsestat.Execute(); } }
static void Main(string[] args) { if (args.Length == 0) { Console.WriteLine(" █████╗ ███╗ ██╗██████╗ ██████╗ ██╗██╗ ██╗ ███████╗ ██████╗██████╗ ██╗██████╗ ████████╗\r\n██╔══██╗████╗ ██║██╔══██╗██╔══██╗██║╚██╗ ██╔╝ ██╔════╝██╔════╝██╔══██╗██║██╔══██╗╚══██╔══╝\r\n███████║██╔██╗ ██║██║ ██║██████╔╝██║ ╚████╔╝ ███████╗██║ ██████╔╝██║██████╔╝ ██║ \r\n██╔══██║██║╚██╗██║██║ ██║██╔══██╗██║ ╚██╔╝ ╚════██║██║ ██╔══██╗██║██╔═══╝ ██║ \r\n██║ ██║██║ ╚████║██████╔╝██║ ██║██║ ██║ ███████║╚██████╗██║ ██║██║██║ ██║ \r\n╚═╝ ╚═╝╚═╝ ╚═══╝╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚══════╝ ╚═════╝╚═╝ ╚═╝╚═╝╚═╝ ╚═╝"); Console.WriteLine("Made by Andriy Kaminskyy IKNI PI-32"); Console.Write("Usage: >ConsoleInterpreter.exe <filepath>"); Console.ReadKey(); } else if (File.Exists(args[0])) { Lexer lex = new Lexer(File.ReadAllText(args[0])); Parser parser = new Parser(lex, new FunctionManager()); IContext context = new Context(new FunctionManager(), new ConsoleInputManager(), new FileManager(), args[0]); try { IStatement cur = parser.BuildStatement(); while (cur != null) { cur.Execute(context); cur = parser.BuildStatement(); } } catch (SyntaxException e) { Console.WriteLine($"SyntaxError: {e.Message}"); } Console.Write("Program end."); Console.ReadKey(); } else { Console.WriteLine($"File {args[0]} does not exist."); Console.ReadKey(); } }