Questions tagged [sqlobject]

SQLObject is a free and open-source (LGPL) Python object-relational mapper. SQLObject supports a number of backends: MySQL/MariaDB (with a number of DB API drivers: MySQLdb, mysqlclient, mysql-connector, PyMySQL, mariadb), PostgreSQL (psycopg2, PyGreSQL), SQLite (builtin sqlite, pysqlite). Works under Python 2.7 and 3.4+.

What is SQLObject

SQLObject is a free and open-source (LGPL) Python object-relational mapper. Your database tables are described as classes, and rows are instances of those classes. SQLObject is meant to be easy to use and quick to get started with.

SQLObject supports a number of backends: MySQL/MariaDB (with a number of DB API drivers: MySQLdb, mysqlclient, mysql-connector, PyMySQL, mariadb), PostgreSQL (psycopg2, PyGreSQL, partially pg8000 and py-postgresql), SQLite (builtin sqlite, pysqlite, partially supersqlite); connections to other backends

  • Firebird, Sybase, MSSQL and MaxDB (also known as SAPDB) - are less debugged).

Python 2.7 or 3.4+ is required.

Where is SQLObject

Site: http://sqlobject.org

Download: https://pypi.org/project/SQLObject/

News and changes: http://sqlobject.org/News.html

Mailing lists: https://sourceforge.net/p/sqlobject/mailman/

Development: http://sqlobject.org/devel/

Developer Guide: http://sqlobject.org/DeveloperGuide.html

Example

Install:

$ pip install sqlobject

Create a simple class that wraps a table:

>>> from sqlobject import *
>>>
>>> sqlhub.processConnection = connectionForURI('sqlite:/:memory:')
>>>
>>> class Person(SQLObject):
...     fname = StringCol()
...     mi = StringCol(length=1, default=None)
...     lname = StringCol()
...
>>> Person.createTable()

Use the object:

>>> p = Person(fname="John", lname="Doe")
>>> p
<Person 1 fname='John' mi=None lname='Doe'>
>>> p.fname
'John'
>>> p.mi = 'Q'
>>> p2 = Person.get(1)
>>> p2
<Person 1 fname='John' mi='Q' lname='Doe'>
>>> p is p2
True

Queries:

>>> p3 = Person.selectBy(lname="Doe")[0]
>>> p3
<Person 1 fname='John' mi='Q' lname='Doe'>
>>> pc = Person.select(Person.q.lname=="Doe").count()
>>> pc
1
73 questions
2
votes
4 answers

IronPython db-api 2.0

Does anyone know which if any db-api 2.0 drivers work with IronPython? If so, has anyone tried using it with SQLAlchemy, SQLObject or the Django ORM?
Vasil
  • 36,468
  • 26
  • 90
  • 114
2
votes
1 answer

Possible to get a generator over a custom SQLObject Select call?

I'm using the SQLObject ORM in Python, and I want to be able to iterate over a generator (of the row objects) in the same way I would Table.select(...), but what I can get from doing this method call is too restrictive, even using filter(). I want…
Benjamin R
  • 555
  • 6
  • 25
2
votes
1 answer

SqlObject and SqlBuilder IN() function with string values

as my first post here, I would like to warn that I looked as well as I could on the web but nothing that solved it. I am using python 2.7 and latest version of sqlobject lib. I faced that when calling the IN() function with a list or tuple of…
DFE
  • 126
  • 9
2
votes
1 answer

How to call queryAll method

I was going through the instructions specified under SQL statements, and I got stuck at this line: rows = connection.queryAll(query) From where are we getting this connection object? Because I am sure this is not the object obtained from this…
Kaushik Shrestha
  • 932
  • 1
  • 11
  • 26
2
votes
2 answers

SQLObject install without internet

Trying to setup a python flask server in a controlled environment, no access to internet # python setup.py install Traceback (most recent call last): File "setup.py", line 9, in use_setuptools() File…
tesgo
  • 66
  • 1
  • 7
2
votes
1 answer

Python SQL Object selecting data by dictionary and date

I am using SQLObject, a wrapper for python to manage SQL Queries, with Python 2.7. I know I can select data by using a dictionary such as: restrictions = { ... } selection = sql_table.selectBy(**restrictions).orderBy('-createdtime') I can also…
OmegaNalphA
  • 610
  • 1
  • 6
  • 17
2
votes
1 answer

Update value checking previous one - SQLObject

In an application already deployed, using SQLObject, I need to update a value only if the previous value match a certain value. The equivalent sql could be: UPDATE jobs SET status='150' WHERE id=1234 AND status='100' I need this because we have…
KumZ
  • 565
  • 12
  • 20
2
votes
1 answer

How to bundle an app including SQLObject using cx_Freeze

Background I'm using cx_Freeze to build Windows and Mac packages of my application; the build executes successfully on both platforms resulting in an msi on Windows and dmg/app on Mac which I can install. Problem The problem occurs when I run the…
Alex
  • 41
  • 3
2
votes
2 answers

SQLObject throws: Unknown database 'dbname?charset=utf8'

I've got third-party Python script, it looks like it has to connect to MySQL database by means of SQLObject package. Considering I've provided correct DSN, the script throws sqlobject.dberrors.OperationalError: Unknown database …
Estus Flask
  • 206,104
  • 70
  • 425
  • 565
2
votes
2 answers

SQL get data out of BEGIN; ...; END; block in python

I want to run many select queries at once by putting them between BEGIN; END;. I tried the following: cur = connection.cursor() cur.execute(""" BEGIN; SELECT ...; END;""") res = cur.fetchall() However, I get the error: psycopg2.ProgrammingError: no…
Claudiu
  • 224,032
  • 165
  • 485
  • 680
2
votes
1 answer

How to implement callback on connection drop event using SQLObject?

I'm using a Python script that does certain flow control on our outgoing mail messages, mostly checking whether a user is sending spam. The script establishes a persistent connection with a database via a SQLObject. Under certain circumstances, the…
nKn
  • 13,691
  • 9
  • 45
  • 62
2
votes
3 answers

SQLObject: how to remove first N objects from the table?

I have an application that keeps track on items and uses SQLObject python ORM. At some point of time app checks if table is not too big, and if it's more than 10000 items in table it removes first N items so it's 10000 items in the table. What is…
grigoryvp
  • 40,413
  • 64
  • 174
  • 277
2
votes
1 answer

SQLObject - Updating Many Records

I am using SQLObject with an sqlite database to store document records. The documents have been scanned the document information stored in a text file. I need to read all these text files (about 800) and load document records from them (average 40…
jimscafe
  • 1,081
  • 2
  • 14
  • 24
1
vote
0 answers

Migrating from SQLObject to SQLAlchemy :: Can SQLAlchemy support zero caching and autoload table updates?

I want to know if SQLAlchemy can support instant loading of the current state of an object from the database when another process updates some attributes of the same object. I want to mention, I am migrating from SQLObject to SQLAlchemy. Using…
user866937
  • 203
  • 2
  • 9
1
vote
1 answer

Good idea/Best way to extend Spine.Model

[background below] I've got my data modelled out in SQLObject in Python on the back-end. Right now I'm converting an SQLObject to a dict, and grabbing all the keys from the dict and then exporting that as a JSON document (so just a JavaScript…
tkone
  • 22,092
  • 5
  • 54
  • 78