Using pysqlite2

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • lolmcbride@googlemail.com

    #1

    Using pysqlite2

    Is it possible to use this for sending triggers to a sqlite db?Could
    someone provide me with an example of how to do this please?
    Thanks

  • Dennis Benzinger

    #2
    Re: Using pysqlite2

    lolmcbride@goog lemail.com wrote:[color=blue]
    > Is it possible to use this for sending triggers to a sqlite db?Could
    > someone provide me with an example of how to do this please?
    > Thanks[/color]

    Do you want to implement a trigger for a SQLite database in Python?

    That won't work. Triggers in SQLite can only contain UPDATE, INSERT,
    DELETE and SELECT statements http://sqlite.org/lang_createtrig ger.html>.

    Bye,
    Dennis

    Comment

    • Gerhard Häring

      #3
      Re: Using pysqlite2

      -----BEGIN PGP SIGNED MESSAGE-----
      Hash: SHA1

      Dennis Benzinger wrote:[color=blue]
      > lolmcbride@goog lemail.com wrote:[color=green]
      >> Is it possible to use this for sending triggers to a sqlite db?Could
      >> someone provide me with an example of how to do this please?
      >> Thanks[/color]
      >
      > Do you want to implement a trigger for a SQLite database in Python?
      >
      > That won't work. Triggers in SQLite can only contain UPDATE, INSERT,
      > DELETE and SELECT statements http://sqlite.org/lang_createtrig ger.html>.[/color]

      Yes, but you can fake it.

      You can create a new SQL function using pysqlite's create_function , and
      then just call that function in the trigger. In that Python function from
      the trigger, you can then even access SQLite again.

      I've attached a quick-and-dirty example.

      Note that exceptions in functions get ignored currently, so you better
      implement a try-except with some kind of logging during development,
      otherwise you will wonder why nothing happens.

      Also, older pysqlite releases won't provide useful error messages if you
      have errors in the SQL you send to executescript() . Using a recent pysqlite
      release is recommended if you plan to use executescript() .

      - -- Gerhard
      -----BEGIN PGP SIGNATURE-----
      Version: GnuPG v1.4.2.2 (GNU/Linux)
      Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

      iD8DBQFEgMQrdIO 4ozGCH14RArFaAK CU8lgwidMoNQ0GG KVwJ2GV9xPF8ACf TDhv
      QVHvudLfoDGiIyF gHe5w6L4=
      =bfUa
      -----END PGP SIGNATURE-----

      Comment

      • xera121

        #4
        Re: Using pysqlite2

        Many thanks Gerhard - the solution you offer is workable in the scope
        of my project.
        Gracias muchacho
        Xera121

        Comment

        Working...