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
0
votes
1 answer

using eval to programmatically define an SQLQuery q object

I'm using SQLObject and want to programmatically build a query using the .q objects (or some other way) -- but do not want to revert to actual SQL. I'm trying to do something like: column = 'name' value =…
tkone
  • 22,092
  • 5
  • 54
  • 78
0
votes
1 answer

Accessing data for SQL object inner join

I am trying to get this inner join to show output the the title and date. Is only returning the sql object that gives details on object. this is result. I can access num_rows but just gives me int(11) for the number of records, don't know how to…
0
votes
1 answer

JDBI, Model Mapper and SQL Object Queries

I'm using Model Mapper with JDBI, but I'm not able to use model mapper with SQL Object Queries. For example I have this select @SqlQuery("select * from example") and documentation says I have to use a ResultSetMapper or ResultSetMapperFactory to…
Silvia
  • 11
  • 5
0
votes
1 answer

sqlobject: No connection has been defined for this thread or process

I'm using sqlobject in Python. I connect to the database with conn = connectionForURI(connStr) conn.makeConnection() This succeeds, and I can do queries on the connection: g_conn = conn.getConnection() cur = g_conn.cursor() cur.execute(query) res…
Claudiu
  • 224,032
  • 165
  • 485
  • 680
0
votes
1 answer

SQL Server: Can INFORMATION_SCHEMA Tell Me When a SQL Object Was Created?

Given: I added a non-nullable foreign key to a table. I settled on a way to populate the foreign key with default values. I checked in both changes to a re-runnable DB creation script. Other developers ran this script, and now they have the foreign…
Jim G.
  • 15,141
  • 22
  • 103
  • 166
0
votes
1 answer

SQLObject: How do I prevent a specific class from being cached?

SQLObject caching is very aggressive for me. Can I prevent one specific class from being cached?
Sergej Andrejev
  • 9,091
  • 11
  • 71
  • 108
0
votes
1 answer

CONCAT_WS in sqlalchemy?

In my sqlobject implementation I have the following line: members = Member.select("CONCAT_WS(' ', member.first_name, member.last_name, member.personal_code_number, member.mail) like " + Member.sqlrepr('%' + query + '%')) I want to convert that to…
Markus Johansson
  • 3,733
  • 8
  • 36
  • 55
0
votes
2 answers

SQLobject installed but IMDbPY fail

I tried using SQLobject from IMDbPY and Python said the driver didn't work- I'm running PostgreSQL 9.2. C:\Users\dom\AppData\Roaming\Python\Scripts>python imdbpy2sql.py -d /imdb -u 'postgres://sid:asdf@host/imdb' Traceback (most recent call…
trianIMDB
  • 1
  • 2
0
votes
1 answer

Closing an SQLObject Connection

Is it possible to manually close an SQLObject Connection once it has been opened? I am trying to delete a database file once it has been used, but it seems that the open connection to the database file is stopping me from doing so. For…
JimmidyJoo
  • 10,503
  • 7
  • 27
  • 30
0
votes
1 answer

Using illegal names in MySQL through SQLObject

How to use illegal names for MySQL with SQLObject? In pure SQL it is possible to use backquotes, say: SELECT `select from` FROM table1 WHERE 1; ...can be used to select the field called select from. Is it possible to tell SQLObject to utilize…
Alex
  • 43,191
  • 44
  • 96
  • 127
0
votes
1 answer

Error while importing SQLObject on Windows

I am getting following error while importing SQLObject on Window. Does anyone knows what is this error about and how to solve it? ============================== from sqlobject import * File…
Vijayendra Bapte
  • 1,378
  • 3
  • 14
  • 23
0
votes
2 answers

Executing SQL LIKE in SQLObject

Is there a pretty way to execute an SQL statement with a LIKE in SQLObject? This one works, but it's somewhat ugly: fields = Foo.select("field LIKE '%%%s%%'" % bar)
Alex
  • 43,191
  • 44
  • 96
  • 127
-1
votes
1 answer

How to get the database row id in a SQLObject Python class method to mimic AddRemoveName

When creating a table with SQLObject, it generates a primary key ID that is not in the Class definition ( ex Person and Address) This ID must be used to point to a related table ( foreign key) As far as i know (beginner for SQLObject i see no way to…
Ghisbo
  • 3
  • 1
  • 2
1 2 3 4
5