Giter Site home page Giter Site logo

Comments (9)

thirashima avatar thirashima commented on May 31, 2024

It's the "USE" statement (line 148, in sqlalchemy_backend.py). Postgres always connects to a database using the connect string, so the USE is not needed. A possible fix would be to change the "if" statement that checks for ":memory:" to check to see if it is postgres as well.

from bottle-cork.

jlutz777 avatar jlutz777 commented on May 31, 2024

To implement this properly, it should be broken out into its own class instead of the inline postgres-specific code, but for those that need it, this is my Postgres workaround. I wrote some unit tests, and it seems to work for Postgresql. As a warning, I did NOT test this thoroughly with other database types to make sure I didn't break anything.

    if initialize:
        # Create new database if needed.
        db_url, db_name = db_full_url.rsplit('/', 1)
        isPostgres = False

        # Postgresql needs to be treated differently because it always
        # connects to a database ... template1 is used as a dummy db
        # in order to create the db we want
        if db_url.startswith('postgresql'):
            isPostgres = True
            db_url += '/template1'

        self._engine = create_engine(db_url)

        # Postgresql won't let you create a database in a transaction
        if isPostgres:
            self._engine.raw_connection().set_isolation_level(0)

        try:
            self._engine.execute("CREATE DATABASE %s" % db_name)
        except Exception, e:
            log.info("Failed DB creation: %s" % e)

        # Postgresql doesn't use the USE statement, but make
        # sure you set it back to using translations
        if isPostgres:
            self._engine.raw_connection().set_isolation_level(1)
        # SQLite in-memory database URL: "sqlite://:memory:"
        elif db_name != ':memory:':
            self._engine.execute("USE %s" % db_name)

    else:
        self._engine = create_engine(db_full_url)

from bottle-cork.

astubbs avatar astubbs commented on May 31, 2024

Whipped up some commits based on the above, let me know what you think: astubbs@ee6da49

from bottle-cork.

astubbs avatar astubbs commented on May 31, 2024

The tests don't seem to be self contained in tox. What's the process for getting this tested properly?

from bottle-cork.

astubbs avatar astubbs commented on May 31, 2024

Ignore that sha, the branch is here: https://github.com/astubbs/bottle-cork/tree/postgres-fix

from bottle-cork.

jlutz777 avatar jlutz777 commented on May 31, 2024

I didn't test it, but your branch doesn't look quite right. You are calling create_engine twice for postgresql and not setting the isolation level back. It looks like a copy-paste mistake.

from bottle-cork.

astubbs avatar astubbs commented on May 31, 2024

No, I added it on purpose. How can you create the database, and connect to it - I understood you have to connect directly to the db, so you'd need to reconnect, no?
But yes you were right about turning the transactions back on, I've put that back in.
Do you know if the tests should all pass in origin/master by just simply running tox?

commits: https://github.com/astubbs/bottle-cork/commits/postgres-fix

from bottle-cork.

jlutz777 avatar jlutz777 commented on May 31, 2024

I see what you did now, sorry about that. As far as the tests, I'm not sure. As you can guess since I posted this a while ago, I didn't get around to actually implementing it and figuring out the tests. Maybe Federico can help with some direction on running the tests.

from bottle-cork.

botzill avatar botzill commented on May 31, 2024

Hi.

I wanted to know what is the status of this issue? Was it fixed/merged? I see there is some fix on it.

Thx.

from bottle-cork.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.