Ejemplo n.º 1
0
        public async Task <IEnumerable <IDictionary <string, string> > > ExecuteSql(string sql)
        {
            sql = sql.Trim();
            var selectKeyword = Keywords.Select.ToString();
            var createKeyword = Keywords.Create.ToString();
            var insertKeyword = Keywords.Insert.ToString();
            var deleteKeyword = Keywords.Delete.ToString();
            var updateKeyword = Keywords.Update.ToString();

            if (sql.StartsWithKeyword(selectKeyword, ' ', '*'))
            {
                return(await _projectionEngine.ExecuteSelectStatement(sql));
            }

            if (sql.StartsWithKeyword(createKeyword, ' '))
            {
                await _creationEngine.ExecuteCreateStatement(sql);

                goto ReturnEmpty;
            }

            if (sql.StartsWithKeyword(insertKeyword, ' '))
            {
                await _insertionEngine.ExecuteInsertStatement(sql);

                goto ReturnEmpty;
            }

            if (sql.StartsWithKeyword(deleteKeyword, ' '))
            {
                await _deletionEngine.ExecuteDeleteStatement(sql);

                goto ReturnEmpty;
            }

            if (sql.StartsWithKeyword(updateKeyword, ' '))
            {
                await _updateEngine.ExecuteUpdateStatement(sql);

                goto ReturnEmpty;
            }

            throw new SyntacticErrorException(sql);

ReturnEmpty:
            return(new List <IDictionary <string, string> >());
        }