Paul Otto Seidon | 7 Jan 16:03 2016
Picon

How to order a table by fields of an other table connected to the first one by ForeignKey()

Hi all,

this seems somehow related to a recent post asking about "querying for 
foreign key". Here as well, I guess, tables have to be joined, but I 
don't see how to pack this into a single ORDERBY clause.

The main table is Entry, which owns _status = ForeignKey( "Status"). 
Status owns a field 'value' besides some other fields. Now I would like 
the Entry rows I select by some other criterion (e.g. their priority) be 
ordered by the value field of the Status of the Entry.

When I ORDERBY Status.q._value then SQLOBJECT correctly tells me, that 
Entry doesn't own a _value field. All other combinations don't work 
neither. 

This has to be done more SQL-ish, right?

Anyone willing to help me out here?

Cheers
Paul

------------------------------------------------------------------------------
Oleg Broytman | 24 Dec 21:10 2015
X-Face
Gravatar

SQLObject 2.2.0b2 and 3.0.0a2

Hello!

I'm pleased to announce versions 2.2.0b2 and 3.0.0a2 of SQLObject.

What's new in SQLObject since 2.2.0b1 (and 3.0.0a1)
===================================================

* Columns for ForeignKey are created using idType of the referenced
  table.

* Added new test help setupCyclicClasses to setup classes with mutual
  references.

Contributor for this release is Nathan Edwards.

For a more complete list, please see the news:
http://sqlobject.org/News.html

What is SQLObject
=================

SQLObject is an 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, PostgreSQL, SQLite,
Firebird, Sybase, MSSQL and MaxDB (also known as SAPDB).

Python 2.6 or 2.7 is required.

(Continue reading)

Nathan Edwards | 22 Dec 18:50 2015
Picon

Strange ForeignKey behavior...


A number of my students used some form of the ForeignKey abuse shown
below. The first one B(anInt=2,afk=a.id) is pretty benign (though
unnecessary), but the really strange one is B(anInt=4,afk='Strange!').
At least with sqlite3 as the backend, this is stored in the database as
a string (!!!!), even though the schema declares it as an INT and
formalizes the reference constraint to table A's id (also an INT).

Python 2.7.3, SQLObject version 2.1.2.

from sqlobject import *

class A(SQLObject):
    aFloat = FloatCol()

class B(SQLObject):
    anInt = IntCol()
    afk = ForeignKey("A")

sqlhub.processConnection = connectionForURI('sqlite:test.db3?debug=1')

A.dropTable(ifExists=True)
B.dropTable(ifExists=True)
A.createTable()
B.createTable()

a = A(aFloat=1.0)

b = B(anInt=1,afk=a)
b = B(anInt=2,afk=a.id)
(Continue reading)

QQ邮箱 | 20 Dec 14:38 2015

sqlobject how to limit return column list

Hi. I love sqlojbect very much.

Please forgive my poor English,

Example code:

class MyUser(SQLObject):
  name=StringCol()
  mobile=StringCol()
  ….
  depart=StringCol()
  sex =StringCol()

i want limit return column,
data=MyUser.selectBy(depart=‘xxx’,items=[’name’,’sex'])

only name and sex column in data.

Any help would be much appreciated!

------------------------------------------------------------------------------
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss
joshua | 16 Dec 00:49 2015
Picon

sqlobject one-to-many join question

So I've been absolutely loving sqlobject, until I get to actually get to making relations between tables.  At this point, I feel that the 'documentation' covers some points, but really doesn't explain other bits very well at all.

So I have 2 problems:

The first is that when running my program the first time, it fails to create all the tables (using .createTable(ifNotExists = True))  and only several tables are generated, before it errors out with:
sqlobject.dberrors.OperationalError: Can't create table `rainmeter`.`#sql-65c_209` (errno: 150 "Foreign key constraint is incorrectly formed")
Then running it again causes the rest of the tables to be created.
 
Here's the relevant parts of my class definitions:
 
class Table_Sensors(sqlobject.SQLObject):
    name = sqlobject.StringCol(length=32)
    group = sqlobject.ForeignKey("Table_Groups")
class Table_Groups(sqlobject.SQLObject):
    name = sqlobject.StringCol(length=32)
    sensors = sqlobject.MultipleJoin("Table_Sensors")
Table_Sensors.createTable(ifNotExists = True)
Table_Groups.createTable(ifNotExists = True)
 
Anyways, this is inconvenient, but it does work after running it again, so I can put up with it.  The real problem I've been having is that I'm having trouble figuring out how to select all entries in Table_Sensors that point to a specific Table_Groups.
 
Here's one example I've tried:
Table_Groups.select(Table_Groups.q.name=="Feels_Like", Table_Groups.q.sensors==Table_Sensors.q.group, orderBy=Table_Sensors.q.sort_order)
 
But no matter what I try, even a much simpler query, It just spits back:
AttributeError: Table_Groups instance has no attribute 'sensors'
 
As a side-note, I think some of the things I'm trying to do, I could use j-magic for, but the section on that is incredibly short, and I haven't been able to get that to work either :/
------------------------------------------------------------------------------
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss
joshua | 14 Dec 08:34 2015
Picon

sqlobject with wsgi

I seem to be having troubles getting sqlobject to play nicely with wsgi.

In short, sqlobject seems to be returning the same data that was fetched 
before each time, until Apache is restarted.

Example code:  (much simplified)

now = Table_Now.get(1)
data["some_field"] = now.some_field
//do something with data{}

but even though the row being returned (I simplified it to the code 
above with a single row to try to pinpoint the problem) is actually 
being changed in the SQL db (mySQL) sqlobject always returns the same, 
old data...

I did see mentioned somewhere about "sqlobject.wsgi_middleware," but I 
can't seem to figure out how that is supposed to be implemented, and 
unfortunatly, there doesn't seem to be any documentation covering that 
anywhere...

Any help would be much appreciated!

------------------------------------------------------------------------------
Gustavo A. Díaz | 26 Aug 19:07 2015
Picon

DateCol format on default

Hi,

Is there anyway to change for date format on DateCol default value?

I use DateCol(default=datetime.strftime(datetime.now(), '%d-%m-%Y') but does not work:

unhandled formencode.api.Invalid "expected a date/time string of the '%Y-%m-%d' format in the DateTimeCol 'modified', got <class 'str'> '26-08-2015' instead"

Thanks!

--

Gustavo A. Díaz
GDNet - www.gdnet.com.ar
"Servicios TI para tus necesidades"

------------------------------------------------------------------------------
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss
Taia Modlin | 24 Jun 18:13 2015
Picon

querying with foreign key

Hello,

I was wondering if it is possible to filter a table based on a field from it's foreign key.

Thanks
------------------------------------------------------------------------------
Monitor 25 network devices or servers for free with OpManager!
OpManager is web-based network management software that monitors 
network devices and physical & virtual servers, alerts via email & sms 
for fault. Monitor 25 devices for free with no restriction. Download now
http://ad.doubleclick.net/ddm/clk/292181274;119417398;o
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss
Oleg Broytman | 19 Jun 16:40 2015
X-Face
Gravatar

SQLObject 2.2.0b1

Hello!

I'm pleased to announce version 2.2.0b1, the first beta of the upcoming
release of branch 2.2 of SQLObject.

What's new in SQLObject
=======================

Features & Interface
--------------------

* Add function col.use_microseconds(True/False). Default is to use
  microseconds (True).

* For MSSQL use datetime2(6) and time(6) columns.

Minor features
--------------

* Minor refactoring to pave the way to Python 3 was merged from
  `SQLObject 1.6.7`_.

Bugfixes
--------

* Fix a bug: mxDateTime doesn't support microseconds; %s in mxDateTime
  format means ticks.

Contributor for this release is Andrew Ziem.

For a more complete list, please see the news:
http://sqlobject.org/News.html

What is SQLObject
=================

SQLObject is an 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, PostgreSQL, SQLite,
Firebird, Sybase, MSSQL and MaxDB (also known as SAPDB).

Python 2.6 or 2.7 is required.

Where is SQLObject
==================

Site:
http://sqlobject.org

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

Mailing list:
https://lists.sourceforge.net/mailman/listinfo/sqlobject-discuss

Archives:
http://news.gmane.org/gmane.comp.python.sqlobject

Download:
https://pypi.python.org/pypi/SQLObject/2.2.0b1dev-20150619

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

Oleg.
--

-- 
     Oleg Broytman            http://phdru.name/            phd <at> phdru.name
           Programmers don't die, they just GOSUB without RETURN.

------------------------------------------------------------------------------
aseiden | 9 Jun 01:46 2015

Versioning with SQLRelatedJoin?

Is it possible to combine SQLObject Versioning with a SQLRelatedJoin?

Here's what I'm trying to do:  I have a many-to-many relationship 
between two classes, "Asset" and "Cart".  A Cart can have a bunch of 
Assets, and Assets can belong to more than one cart.

I'd like to be able to version changes to the assets that are in the 
cart (i.e. the cart.assets field) as well as the other

Here's a simplified version of what I'm doing:

#!/usr/bin/env python

import os, time, datetime
from sqlobject import *
from sqlobject.versioning import Versioning

class Asset(SQLObject):
     name = StringCol(unique=True, length=255)
     author = StringCol(length=20, default=os.getenv('USER'))
     date = DateTimeCol(default=DateTimeCol.now)
     notes = StringCol(default='')
     savedcarts = SQLRelatedJoin('Cart')

class Cart(SQLObject):
     """ A saved list of AssetItems. Usually created in RepoBrowse. """
     name = StringCol(unique=True, length=255)
     author = StringCol(length=20, default=os.getenv('USER'))
     date = DateTimeCol(default=DateTimeCol.now)
     notes = StringCol(default='')
     assets = SQLRelatedJoin("Asset", addRemoveName="Asset")

     versions = Versioning()

     def dumpVersions(self):
         for i, vers in enumerate(self.versions):
             allAssetNames = [ass.name for ass in vers.assets]
             print "#%d %s %-40.40s %s     Assets: %s"%(i, vers.name, 
vers.notes, vers.date, ','.join(allAssetNames))

if __name__ == '__main__':
     # Make DB
     dbname = os.path.abspath("joinV.sq3")
     os.remove(dbname)
     dburl = 'sqlite://%s'%dbname
     connection = connectionForURI(dburl)
     sqlhub.processConnection = connection

     Asset.createTable(ifNotExists=True)
     Cart.createTable(ifNotExists=True)

     # Make some assets
     assFoo = Asset(name="Foo")
     assBar = Asset(name="Bar")
     assBaz = Asset(name="Baz")
     assAck = Asset(name="Ack")

     # Make a cart
     cart = Cart(name="Savedcart1")

     for i, ass in enumerate([assFoo, assBar, assBaz, assAck]):
         cart.addAsset(ass)
         cart.notes='submission %d--added "%s"'%(i, ass.name)

     cart.dumpVersions()

This outputs:

#0 Savedcart1 2015-06-08 16:36:59     Assets: Foo,Bar,Baz,Ack
#1 Savedcart1 submission 0--added "Foo" 2015-06-08 16:36:59     Assets: 
Foo,Bar,Baz,Ack
#2 Savedcart1 submission 1--added "Bar" 2015-06-08 16:36:59     Assets: 
Foo,Bar,Baz,Ack
#3 Savedcart1 submission 2--added "Baz" 2015-06-08 16:36:59     Assets: 
Foo,Bar,Baz,Ack

What I'd like to see is #0 have vers.assets only contain "Foo", #1 have 
only "Foo" and "Bar", etc.
Is this possible with SQLObject's versioning?

Thanks much!
Alex Seiden

p.s. I'm using Linux (CentOS 6.6), python 2.7, and SQLObject 1.6.  I 
would update to a more recent SQLObject if it would matter, but I didn't 
see anything in the release notes that seemed relevant.  And FWIW, my 
'real' app uses mysql, but sqlite was easier for the example.

------------------------------------------------------------------------------
Oleg Broytman | 27 Mar 21:25 2015
X-Face
Gravatar

SQLObject 3.0.0a1

Hello!

I'm pleased to announce version 3.0.0a1, the first alpha of the upcoming
release of branch 3.0 of SQLObject.

What's new in SQLObject
=======================

Features
--------

* Support for Python 2 and Python 3 with one codebase!
  (Python version >= 3.4 currently required.)

Minor features
--------------

* Use fdb adapter for Firebird.

* PyDispatcher (>=2.0.4) was made an external dependency.

Development
-----------

* Source code was made flake8-clean.

Documentation
-------------

* Documentation is published at http://sqlobject.readthedocs.org/ in
  Sphinx format.

Contributors for this release are Ian Cordasco, Neil Muller,
Lukasz Dobrzanski, Gregor Horvath.

For a more complete list, please see the news:
http://sqlobject.org/News.html

What is SQLObject
=================

SQLObject is an 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, PostgreSQL, SQLite,
Firebird, Sybase, MSSQL and MaxDB (also known as SAPDB).

Python 2.6, 2.7 or 3.4+ is required.

Where is SQLObject
==================

Site:
http://sqlobject.org

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

Mailing list:
https://lists.sourceforge.net/mailman/listinfo/sqlobject-discuss

Archives:
http://news.gmane.org/gmane.comp.python.sqlobject

Download:
https://pypi.python.org/pypi/SQLObject/3.0.0a1dev-20150327

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

Oleg.
--

-- 
     Oleg Broytman            http://phdru.name/            phd <at> phdru.name
           Programmers don't die, they just GOSUB without RETURN.

------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the 
conversation now. http://goparallel.sourceforge.net/

Gmane