03.09.2023 15:01, Adriano dos Santos Fernandes wrote:
> On 02/09/2023 22:51, Adriano dos Santos Fernandes wrote:
>> But it does it with help of an enhanced engine's IAttachment::prepare2
>> method.
>>
>> This method has a new parameter "unsigned* stopLength".
>
> One point I'm in doubt with this api is that in case of semantic errors
> after parse.
>
> If I try to compile:
>
> select '1' + 1 from rdb$database; select 2 from rdb$database;
>
> Engine must consume first statement and report its length.
>
> But engine is going to report an error too.
>
> Do we have any other API that return output parameters even in case of
> error status?
What if instead of attempt of preparing statement, this new API will attempt
to just parse it and return success/failure ? Then, on success, ISQL will
pass corresponding part of input to the usual sequence of prepare/describe/
execute/fetch... APIs.
I.e. introduce new parse() method that will return count of successfully
parsed bytes, if any. Return 0, if text contains no valid statement.
Also, it is not clear what ISQL should do if text entered contains both valid
and not complete statements, for example:
select 1 from rdbdatabase; select
would it drop the 2nd "select" ? How user should continue typing the incomplete
command ? I.e. should (s)he type the rest
2 from rdbdatabase;
Let me suggest an alternative to the "set terminator" mechanism.
Skipping the very long history of this problem, the AmorphousDB Interact class handles the problem by probing a prospective statement as it is built up line by line by doing a "scan only" parse of the command text. The actual code in the parse looks like this:
bool Parse::isIncompleteStatement(const char* string)
{
if (parser)
return parser->isIncompleteStatement(string);
upcaseIdentifiers = true;
setString(string);
scanOnly = true;
try
{
parse();
}
catch (SyntaxException&)
{
return tokenType == tokenEOF;
}
return false;
}
If scanOnly is set, two things primary things happen. First, the the parser doesn't allocate syntax nodes; all productions return NULL. Second, the parse returns a distinctive SyntaxError exception. As can be seen, a SyntaxError with a Lex token type means that the statement was complete. In addition, there are a few places in the parse that need to check a sub-production, in which was "scanOnly" is temporarily turned off, the sub-production is parsed, checked, and deleted, and "scanOnly" reverted.
The test for "parser" is a hack for when the AmorphousDB parser
has recognized that the statement in question is, in fact, SQL and
needs to pass the function the SQL parser.
AmorphousDB Interact also has an explicit command continuation character that is used only is command files.
I deeply regret having used YACC/BISON for DSQL. I viewed DSQL as a quickie hack for a single customer that thought experimenting with a "compiler compiler" would be a good experience. I later tried to make a BISON parser for C++ and discovered, like many before and after, that it is not capable of parsing the full C++ grammar. I reverted to hard coded recursive descent parsers every since.
I wouldn't much multiple statements on a single interactive line with a 10 foot pole.
ALTER DATABASE BEGIN BACKUP;
<wait for END foevever>
ALTER DATABASE BEGIN BACKUP;
<wait for END foevever>Such queries will cause a problem only when use within stored procedure body.
I have locked at my parser code for processing procedure body.
And step 2 is too naive. The proper way to do that is
Probably fail will be with subrutines in psql?
And CASE statemet also contains END
Regards,
Karol Bieniaszewski
--
You received this message because you are subscribed to the Google Groups "firebird-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebird-deve...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebird-devel/CAHtTfeLOipCadT-AhiR0OQRrukLA5TDfkaMWx5193sT1BC_D7w%40mail.gmail.com.
Probably fail will be with subrutines in psql?
And CASE statemet also contains END
> Internal END does not have ';'
>
> Am I right?
No, you're not. For example this is a valid statement in PSQL:
x = case when y < 10 then 5 else 4 end;
HI! Implemented the ability to work with PSQL without entering SET TERM. The algorithm is based on the parser of incoming tokens and the subsequent determination of the current cursor position. Main tokens "AS" "DECLARE", pair "BEGIN-END" and pair "CASE-END". Implemented the ability to export without SET TERM. Temporarily selected "-XN" option. The "-X" option has not changed. Checked the correct operation in 2 ways. 1) Exported the metadata with the -xn option from a real database (3GB) and imported it to a new database. 2) Metadata from "Interbase" imported to a new database. Then exported and compared with metadata from "Interbase".
Probably fail will be with subrutines in psql?
My suggestion is too naive too, as it won't work if subroutines are present.
The big question here when statement 1, 2, 3 from the script will be executed?
After ENTER? After „;” ?
Why i ask?
You can type SELECT * FROM TABLE ENTER
WHERE 😉
Regards,
Karol Bieniaszewski
Od: Vlad Khorsun
Wysłano: wtorek, 5 września 2023 14:12
Do: firebir...@googlegroups.com
--
You received this message because you are subscribed to the Google Groups "firebird-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebird-deve...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebird-devel/07163403-e3fb-6829-352c-9b40df32a104%40gmail.com.
Guys, this whole discussion is the height of insanity. First, the idea
that a parser for a formal language can be extended to recognize
syntactically invalid statements but still successfully recognize the
correct end of statement is just crazy. And if it could be done, it
shouldn't be done. Are you going to document that various syntax errors
that the system can successfully handle?
The second problem is even more serious. Continuing to process multiple
statements on a line after one has failed (for any reason!) utterly
ignores the most common case where a subsequent statement depends on the
successful execution a preceding statement. How is the poor user going
to figure out what even happened? All he or she really knows is that
something didn't work.
I don't know that status of auto-commit in Firebird, but has anyone
given any thought to the interaction of auto-commit of multiple
statements per line? One line, two statements. The second statement
fails. What gets rolled back?