preparation SQL queries

preparation SQL queries

by Thor Pfosten -
Number of replies: 3

Hi ...


... and thanks for previous help!


now I have another easy (stupid) question, I could  not found

an answer to in the docu. I'd like to create SQL queries.

So I downloaded the demo stuff from trampgeek.


The question is what is to be done on the server (Ubuntu 16.04.)?

I have sqlite3 running ... But after having pasted in the sql - snippet

for a query I get the following error in the browser:


***runtime error***

Error: unable to open database "q1": unable to open database file

Traceback (most recent call last):

  File "__tester__.python3", line 37, in <module>

    universal_newlines=True)

  File "/usr/lib/python3.5/subprocess.py", line 626, in check_output

    **kwargs).stdout

  File "/usr/lib/python3.5/subprocess.py", line 708, in run

    output=stdout, stderr=stderr)

subprocess.CalledProcessError: Command '['sqlite3', 'q1']' returned non-zero exit status 1


During handling of the above exception, another exception occurred:


Traceback (most recent call last):

  File "__tester__.python3", line 40, in <module>

    raise Exception("sqlite3 error: " + str(e))

Exception: sqlite3 error: Command '['sqlite3', 'q1']' returned non-zero exit status 1


Thanks for your help!



Best,

Thor

In reply to Thor Pfosten

Re: preparation SQL queries

by Richard Lobb -

That error means that the command sqlite3 q1 failed because sqlite3 couldn't open the database file q1. I'm not sure why that has happened. We need to explore a bit.

Click the customise checkbox for the question and edit the template to insert a diagnostic print line as follows:

{% for TEST in TESTCASES %}
shutil.copyfile(db_files[0], db_working)  # Copy clean writeable db file
print("Testing with working dir files:", os.listdir())  # <<<<< INSERT THIS LINE
testcode = """{{ TEST.testcode | e('py') }}"""

If you then try to save the question, it should fail to validate. The 'Got' output should start with a line like

Testing with working dir files: ['prog.in', 'q1', 'prog.cmd', '__tester__.python3', '__pycache__', 'q1.db', 'prog.out', 'prog.err']

Tell me what you get.

Richard

In reply to Richard Lobb

Re: preparation SQL queries

by Thor Pfosten -
Hi Richard,

so I just added the following line in the template:

print("Testing with working dir files:", os.listdir())  # <<<<< INSERT THIS LINE

Then I started the query. In the attachment you can see what 
I got. Hope you can guess, what the German words stand for.

Thanks !
Thor 
Attachment coderunner_err_msg.PNG
In reply to Thor Pfosten

Re: preparation SQL queries

by Richard Lobb -

That's odd: there's no output there from the new added line, which should come well before the exception. Are you quite sure the change was saved correctly?

Here's a more drastic change to the template which should prevent the exception and simply display the state of the working directory and the command being run for each test case. Replace everything in the template from the 'for TEST in TESTCASES' line onwards (inclusive) with the following and tell me what you get:

{% for TEST in TESTCASES %}
shutil.copyfile(db_files[0], db_working)  # Copy clean writeable db file
print("Testing with working dir files:", os.listdir())
testcode = """{{ TEST.testcode | e('py') }}"""
extra = """{{ TEST.extra | e('py') }}"""
code_to_run = '\n'.join([prelude, extra, student_answer, testcode])
with open('commands', 'w') as sqlite_commands:
    sqlite_commands.write(code_to_run)

with open('commands') as cmd_input:
    text_input = cmd_input.read()
    try:
        #output = subprocess.check_output(['sqlite3', db_working], input=text_input,
        #         universal_newlines=True)
        output = "Command: " + text_input
        print(output)
    except Exception as e:
        raise Exception("sqlite3 error: " + str(e))

{% if not loop.last %}
print(SEPARATOR)
{% endif %}
{% endfor %}