sqlobject-cvs Mailing List for SQLObject (Page 160)
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
You can subscribe to this list here.
| 2003 |
Jan
|
Feb
|
Mar
(9) |
Apr
(74) |
May
(29) |
Jun
(16) |
Jul
(28) |
Aug
(10) |
Sep
(57) |
Oct
(9) |
Nov
(29) |
Dec
(12) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2004 |
Jan
(7) |
Feb
(14) |
Mar
(6) |
Apr
(3) |
May
(12) |
Jun
(34) |
Jul
(9) |
Aug
(29) |
Sep
(22) |
Oct
(2) |
Nov
(15) |
Dec
(52) |
| 2005 |
Jan
(47) |
Feb
(78) |
Mar
(14) |
Apr
(35) |
May
(33) |
Jun
(16) |
Jul
(26) |
Aug
(63) |
Sep
(40) |
Oct
(96) |
Nov
(96) |
Dec
(123) |
| 2006 |
Jan
(159) |
Feb
(144) |
Mar
(64) |
Apr
(31) |
May
(88) |
Jun
(48) |
Jul
(16) |
Aug
(64) |
Sep
(87) |
Oct
(92) |
Nov
(56) |
Dec
(76) |
| 2007 |
Jan
(94) |
Feb
(103) |
Mar
(126) |
Apr
(123) |
May
(85) |
Jun
(11) |
Jul
(130) |
Aug
(47) |
Sep
(65) |
Oct
(70) |
Nov
(12) |
Dec
(11) |
| 2008 |
Jan
(30) |
Feb
(55) |
Mar
(88) |
Apr
(20) |
May
(50) |
Jun
|
Jul
(38) |
Aug
(1) |
Sep
(9) |
Oct
(5) |
Nov
(6) |
Dec
(39) |
| 2009 |
Jan
(8) |
Feb
(16) |
Mar
(3) |
Apr
(33) |
May
(44) |
Jun
(1) |
Jul
(10) |
Aug
(33) |
Sep
(74) |
Oct
(22) |
Nov
|
Dec
(15) |
| 2010 |
Jan
(28) |
Feb
(22) |
Mar
(46) |
Apr
(29) |
May
(1) |
Jun
(1) |
Jul
(27) |
Aug
(8) |
Sep
(5) |
Oct
(33) |
Nov
(24) |
Dec
(41) |
| 2011 |
Jan
(4) |
Feb
(12) |
Mar
(35) |
Apr
(29) |
May
(19) |
Jun
(16) |
Jul
(32) |
Aug
(25) |
Sep
(5) |
Oct
(11) |
Nov
(21) |
Dec
(12) |
| 2012 |
Jan
(3) |
Feb
(4) |
Mar
(20) |
Apr
(4) |
May
(25) |
Jun
(13) |
Jul
|
Aug
|
Sep
(2) |
Oct
(25) |
Nov
(9) |
Dec
(1) |
| 2013 |
Jan
(6) |
Feb
(8) |
Mar
|
Apr
(10) |
May
(31) |
Jun
(7) |
Jul
(18) |
Aug
(33) |
Sep
(4) |
Oct
(16) |
Nov
|
Dec
(27) |
| 2014 |
Jan
(2) |
Feb
|
Mar
|
Apr
(11) |
May
(39) |
Jun
(8) |
Jul
(11) |
Aug
(4) |
Sep
|
Oct
(27) |
Nov
|
Dec
(71) |
| 2015 |
Jan
(17) |
Feb
(47) |
Mar
(33) |
Apr
|
May
|
Jun
(9) |
Jul
(7) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(8) |
| 2016 |
Jan
(4) |
Feb
(4) |
Mar
|
Apr
|
May
(12) |
Jun
(7) |
Jul
(9) |
Aug
(31) |
Sep
(8) |
Oct
(3) |
Nov
(15) |
Dec
(1) |
| 2017 |
Jan
(13) |
Feb
(7) |
Mar
(14) |
Apr
(8) |
May
(10) |
Jun
(4) |
Jul
(2) |
Aug
(1) |
Sep
|
Oct
(8) |
Nov
(4) |
Dec
(5) |
| 2018 |
Jan
(2) |
Feb
(8) |
Mar
|
Apr
(4) |
May
|
Jun
(6) |
Jul
|
Aug
(1) |
Sep
|
Oct
|
Nov
(1) |
Dec
|
| 2019 |
Jan
(1) |
Feb
(16) |
Mar
(1) |
Apr
(3) |
May
(5) |
Jun
(1) |
Jul
|
Aug
|
Sep
(2) |
Oct
|
Nov
(1) |
Dec
(3) |
| 2020 |
Jan
|
Feb
|
Mar
|
Apr
(1) |
May
(1) |
Jun
|
Jul
|
Aug
(1) |
Sep
|
Oct
(2) |
Nov
|
Dec
(2) |
| 2021 |
Jan
|
Feb
(2) |
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(1) |
Nov
(1) |
Dec
|
| 2022 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(6) |
Oct
(1) |
Nov
(1) |
Dec
(4) |
| 2023 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(1) |
Aug
(3) |
Sep
(2) |
Oct
(2) |
Nov
(4) |
Dec
|
| 2024 |
Jan
|
Feb
(2) |
Mar
|
Apr
|
May
|
Jun
|
Jul
(1) |
Aug
|
Sep
(1) |
Oct
|
Nov
|
Dec
(9) |
| 2025 |
Jan
|
Feb
(4) |
Mar
(2) |
Apr
|
May
|
Jun
|
Jul
|
Aug
(1) |
Sep
|
Oct
|
Nov
(2) |
Dec
(2) |
|
From: <sub...@co...> - 2005-09-22 16:04:26
|
Author: test
Date: 2005-09-22 16:04:21 +0000 (Thu, 22 Sep 2005)
New Revision: 1024
Modified:
SQLObject/trunk/setup.py
Log:
Updated requirement to new version of FormEncode
Modified: SQLObject/trunk/setup.py
===================================================================
--- SQLObject/trunk/setup.py 2005-09-22 15:59:58 UTC (rev 1023)
+++ SQLObject/trunk/setup.py 2005-09-22 16:04:21 UTC (rev 1024)
@@ -43,7 +43,7 @@
license="LGPL",
packages=["sqlobject"] + ['sqlobject.%s' % package for package in subpackages],
scripts=["scripts/sqlobject-admin"],
- install_requires=["FormEncode>=0.2"],
+ install_requires=["FormEncode>=0.2.2"],
extras_require={
'postgresql': ['psycopg'],
'mysql': ['MySQLdb'],
|
|
From: <sub...@co...> - 2005-09-21 14:18:17
|
Author: phd
Date: 2005-09-21 14:18:05 +0000 (Wed, 21 Sep 2005)
New Revision: 1018
Modified:
SQLObject/trunk/docs/Inheritance.txt
Log:
Added a section "Why" describing a typical use of Inheritance.
Modified: SQLObject/trunk/docs/Inheritance.txt
===================================================================
--- SQLObject/trunk/docs/Inheritance.txt 2005-09-21 07:54:21 UTC (rev 1017)
+++ SQLObject/trunk/docs/Inheritance.txt 2005-09-21 14:18:05 UTC (rev 1018)
@@ -3,6 +3,170 @@
Inheritance
-----------
+Why
+~~~
+
+Imagine you have a list or persons, and every person plays a certain role.
+Some persons are students, some are professors, some are employees. Every
+role has different attributes. Students are known by their department and
+year. Professors has department (some attributes are common for all or some
+roles), timetable and other attributes.
+
+How do one implements this in SQL? Well, the obvious approach is to create
+a table Person with a column that describes or name the role, and a table
+for an every role. Then one must write a code that interprets and
+dereferences the role column.
+
+Well, the inheritance machinery described below does exactly this! Only it
+does it automagically and mostly transparent to the user.
+
+First, you create a table Person. Nothing magical here::
+
+ class Person(SQLObject):
+ name = StringCol()
+ age = FloatCol()
+
+Now you need a hierarchy of roles::
+
+ class Role(InheritableSQLObject):
+ department = StringCol()
+
+The magic starts here! You inherit the class from the special root class
+``InheritableSQLObject`` and provide a set of attributes common for all
+roles. Other roles must be inherited from Role::
+
+ class Student(Role):
+ year = IntCol()
+
+ class Professor(Role):
+ timetable = StringCol()
+
+Now you want a column in Person that can be interpreted as the role. Easy::
+
+ class Person(SQLObject):
+ name = StringCol()
+ age = FloatCol()
+ role = ForeignKey("Role")
+
+That's all, really! When asked for its role, Person returns the value of
+its .role attribute dereferenced and interpreted. Instead of returning an
+instance of class Role it returns an instance of the corresponding subclass
+- a Student or a Professor.
+
+This is a brief explanation based on a task people meet most often, but of
+course it can be used far beyond the person/role task. I also omitted all
+details in the explanation. Now look at the real working program::
+
+ from sqlobject import *
+ from sqlobject.inheritance import InheritableSQLObject
+
+ __connection__ = "sqlite:/:memory:"
+
+ class Role(InheritableSQLObject):
+ department = StringCol()
+
+ class Student(Role):
+ year = IntCol()
+
+ class Professor(Role):
+ timetable = StringCol(default=None)
+
+ class Person(SQLObject):
+ name = StringCol()
+ age = FloatCol()
+ role = ForeignKey("Role", default=None)
+
+ Role.createTable()
+ Student.createTable()
+ Professor.createTable()
+ Person.createTable()
+
+ first_year = Student(department="CS", year=1)
+ lecturer = Professor(department="Mathematics")
+
+ student = Person(name="A student", age=21, role=first_year)
+ professor = Person(name="A professor", age=42, role=lecturer)
+
+ print student.role
+ print professor.role
+
+It prints::
+
+ <Student 1 year=1 department='CS'>
+ <Professor 2 timetable=None department='Mathematics'>
+
+You can get the list of all available roles::
+
+ print list(Role.select())
+
+It prints::
+
+ [<Student 1 year=1 department='CS'>, <Professor 2 timetable=None department='Mathematics'>]
+
+Look, you have got a list of Role's subclasses!
+
+If you add a MultipleJoin column to Role you can list all persons for a
+given role::
+
+ class Role(InheritableSQLObject):
+ department = StringCol()
+ persons = MultipleJoin("Person")
+
+ for role in Role.select():
+ print role.persons
+
+It prints::
+
+ [<Person 1 name='A student' age=21.0 roleID=1>]
+ [<Person 2 name='A professor' age=42.0 roleID=2>]
+
+If you you want your persons to have many roles - use RelatedJoin::
+
+ class Role(InheritableSQLObject):
+ department = StringCol()
+ persons = RelatedJoin("Person")
+
+ class Student(Role):
+ year = IntCol()
+
+ class Professor(Role):
+ timetable = StringCol(default=None)
+
+ class Person(SQLObject):
+ name = StringCol()
+ age = FloatCol()
+ roles = RelatedJoin("Role")
+
+ Role.createTable()
+ Student.createTable()
+ Professor.createTable()
+ Person.createTable()
+
+ first_year = Student(department="CS", year=1)
+ lecturer = Professor(department="Mathematics")
+
+ student = Person(name="A student", age=21)
+ student.addRole(first_year)
+ professor = Person(name="A professor", age=42)
+ professor.addRole(lecturer)
+
+ print student.roles
+ print professor.roles
+
+ for role in Role.select():
+ print role.persons
+
+It prints::
+
+ [<Student 1 year=1 department='CS'>]
+ [<Professor 2 timetable=None department='Mathematics'>]
+ [<Person 1 name='A student' age=21.0>]
+ [<Person 2 name='A professor' age=42.0>]
+
+
+Who, What and How
+~~~~~~~~~~~~~~~~~
+
Daniel Savard has implemented inheritance for SQLObject. According to
ObjectMatter_ this is a kind of vertical inheritance. The only difference
is that objects reference their leafs, not parents. Links to parents are
@@ -18,7 +182,6 @@
* This version now seems to works correctly with addColumn, delColumn,
addJoin and delJoin.
-
The following code::
from sqlobject.inheritance import InheritableSQLObject
@@ -44,7 +207,6 @@
position TEXT
)
-
A new class attribute ``_inheritable`` is added. When this new
attribute is set to 1, the class is marked 'inheritable' and a new
columns will automatically be added: childName (TEXT).
@@ -87,7 +249,6 @@
1
Chief
-
You will still be able to ask for the attribute normally:
e.firstName will return Jane and setting it will write the new value in
the person table.
@@ -117,8 +278,10 @@
FROM person, employee WHERE person.first_name = 'Jane'
AND employee.position = 'Chief' AND person.id = employee.id
-Some limitation or notice about this version:
+Limitations and notes
+~~~~~~~~~~~~~~~~~~~~~
+
* Only simple inheritance will work. It is not possible to inherit
from multiple SQLObject classes.
* It is possible to inherit from an inherited class and this will
|
|
From: <sub...@co...> - 2005-09-20 20:55:26
|
Author: phd
Date: 2005-09-20 20:55:21 +0000 (Tue, 20 Sep 2005)
New Revision: 998
Modified:
SQLObject/trunk/sqlobject/inheritance/__init__.py
Log:
Aplied a patch by alexander smishlajev <al...@an...>;
the patch optimizes inheritance machinery by removing hasattr()
that calls getattr() that calls _SO_loadValue() on an every request.
Modified: SQLObject/trunk/sqlobject/inheritance/__init__.py
===================================================================
--- SQLObject/trunk/sqlobject/inheritance/__init__.py 2005-09-20 20:48:30 UTC (rev 997)
+++ SQLObject/trunk/sqlobject/inheritance/__init__.py 2005-09-20 20:55:21 UTC (rev 998)
@@ -163,7 +163,7 @@
#DSM: If we are updating a child, we should never return a child...
if childUpdate: return val
#DSM: If this class has a child, return the child
- if hasattr(val, 'childName'):
+ if 'childName' in cls.sqlmeta.columns:
childName = val.childName
if childName is not None:
return val._childClasses[childName].get(id, connection=connection, selectResults=childResults)
|
|
From: <sub...@co...> - 2005-09-20 20:48:37
|
Author: phd
Date: 2005-09-20 20:48:30 +0000 (Tue, 20 Sep 2005)
New Revision: 997
Modified:
SQLObject/trunk/sqlobject/postgres/pgconnection.py
Log:
Aplied a patch by Tomas <To...@ze...> that uses UnicodeCol instead of StringCol
in case fromDatabase = True and "unicodeCols" flag was passed in the connection arguments.
Modified: SQLObject/trunk/sqlobject/postgres/pgconnection.py
===================================================================
--- SQLObject/trunk/sqlobject/postgres/pgconnection.py 2005-09-20 15:58:41 UTC (rev 996)
+++ SQLObject/trunk/sqlobject/postgres/pgconnection.py 2005-09-20 20:48:30 UTC (rev 997)
@@ -13,7 +13,7 @@
schemes = [dbName, 'postgresql', 'psycopg']
def __init__(self, dsn=None, host=None, port=None, db=None,
- user=None, passwd=None, usePygresql=False,
+ user=None, passwd=None, usePygresql=False, unicodeCols=False,
**kw):
global psycopg, pgdb
self.usePygresql = usePygresql
@@ -78,6 +78,7 @@
dsn.append('port=%d' % port)
dsn = ' '.join(dsn)
self.dsn = dsn
+ self.unicodeCols = unicodeCols
DBAPI.__init__(self, **kw)
# Server version cache
@@ -220,10 +221,15 @@
colData = self.queryAll(colQuery % self.sqlrepr(tableName))
results = []
+ if self.unicodeCols:
+ client_encoding = self.queryOne("SHOW client_encoding")[0]
for field, t, notnull, defaultstr in colData:
if field == primaryKey:
continue
colClass, kw = self.guessClass(t)
+ if self.unicodeCols and colClass == col.StringCol:
+ colClass = col.UnicodeCol
+ kw['dbEncoding'] = client_encoding
kw['name'] = soClass.sqlmeta.style.dbColumnToPythonAttr(field)
kw['dbName'] = field
kw['notNone'] = notnull
|
|
From: <sub...@co...> - 2005-09-20 15:58:52
|
Author: test
Date: 2005-09-20 15:58:41 +0000 (Tue, 20 Sep 2005)
New Revision: 996
Modified:
SQLObject/trunk/sqlobject/postgres/pgconnection.py
Log:
Typo
Modified: SQLObject/trunk/sqlobject/postgres/pgconnection.py
===================================================================
--- SQLObject/trunk/sqlobject/postgres/pgconnection.py 2005-09-16 21:48:36 UTC (rev 995)
+++ SQLObject/trunk/sqlobject/postgres/pgconnection.py 2005-09-20 15:58:41 UTC (rev 996)
@@ -291,7 +291,7 @@
if self.user:
dsn += ' user=%s' % self.user
if self.password:
- dsn += ' passwd=%s' % self.passwd
+ dsn += ' password=%s' % self.password
if self.host:
dsn += ' host=%s' % self.host
conn = self.module.connect(dsn)
|
|
From: <sub...@co...> - 2005-09-16 21:48:40
|
Author: test Date: 2005-09-16 21:48:36 +0000 (Fri, 16 Sep 2005) New Revision: 995 Modified: SQLObject/trunk/docs/sqlobject-admin.txt Log: Forgot link Modified: SQLObject/trunk/docs/sqlobject-admin.txt =================================================================== --- SQLObject/trunk/docs/sqlobject-admin.txt 2005-09-16 21:46:05 UTC (rev 994) +++ SQLObject/trunk/docs/sqlobject-admin.txt 2005-09-16 21:48:36 UTC (rev 995) @@ -68,10 +68,11 @@ ``--egg=EGG_SPEC``: - This is an `Egg <>`_ description that should be loaded. So if you - give ``--egg=ProjectName`` it'll load that egg, and look in - ``ProjectName.egg-info/sqlobject.txt`` for some settings (like - ``db_module`` and ``history_dir``). + This is an `Egg + <http://peak.telecommunity.com/DevCenter/PythonEggs>`_ description + that should be loaded. So if you give ``--egg=ProjectName`` it'll + load that egg, and look in ``ProjectName.egg-info/sqlobject.txt`` + for some settings (like ``db_module`` and ``history_dir``). When finding SQLObject classes, we look in the modules for classes that belong to the module -- so if you import a class from another |
|
From: <sub...@co...> - 2005-09-16 21:46:11
|
Author: test
Date: 2005-09-16 21:46:05 +0000 (Fri, 16 Sep 2005)
New Revision: 994
Modified:
SQLObject/trunk/docs/sqlobject-admin.txt
Log:
Added note on --egg
Modified: SQLObject/trunk/docs/sqlobject-admin.txt
===================================================================
--- SQLObject/trunk/docs/sqlobject-admin.txt 2005-09-16 21:10:05 UTC (rev 993)
+++ SQLObject/trunk/docs/sqlobject-admin.txt 2005-09-16 21:46:05 UTC (rev 994)
@@ -66,6 +66,13 @@
may use wildcards. You can provide multiple ``--class``
arguments, and if any pattern matches the class will be included.
+``--egg=EGG_SPEC``:
+
+ This is an `Egg <>`_ description that should be loaded. So if you
+ give ``--egg=ProjectName`` it'll load that egg, and look in
+ ``ProjectName.egg-info/sqlobject.txt`` for some settings (like
+ ``db_module`` and ``history_dir``).
+
When finding SQLObject classes, we look in the modules for classes
that belong to the module -- so if you import a class from another
module it won't be "matched". You have to indicate its original
|
|
From: <sub...@co...> - 2005-09-16 21:10:17
|
Author: test
Date: 2005-09-16 21:10:05 +0000 (Fri, 16 Sep 2005)
New Revision: 993
Modified:
SQLObject/trunk/sqlobject/manager/command.py
Log:
Read history_dir out of sqlobject.txt; add --egg to all commands; create history directories on demand
Modified: SQLObject/trunk/sqlobject/manager/command.py
===================================================================
--- SQLObject/trunk/sqlobject/manager/command.py 2005-09-16 18:48:54 UTC (rev 992)
+++ SQLObject/trunk/sqlobject/manager/command.py 2005-09-16 21:10:05 UTC (rev 993)
@@ -155,18 +155,18 @@
metavar="NAME",
dest="class_matchers",
default=[])
- parser.add_option('--egg',
- help="Select modules from the given Egg, using sqlobject.txt",
- action="append",
- metavar="EGG_SPEC",
- dest="eggs",
- default=[])
if interactive:
parser.add_option('-i', '--interactive',
help="Ask before doing anything (use twice to be more careful)",
action="count",
dest="interactive",
default=0)
+ parser.add_option('--egg',
+ help="Select modules from the given Egg, using sqlobject.txt",
+ action="append",
+ metavar="EGG_SPEC",
+ dest="eggs",
+ default=[])
return parser
class Command(object):
@@ -228,6 +228,8 @@
if conf and conf.get('database'):
conn = sqlobject.connectionForURI(conf['database'])
sqlobject.sqlhub.processConnection = conn
+ for egg_spec in getattr(self.options, 'eggs', []):
+ self.load_options_from_egg(egg_spec)
self.command()
def classes(self, require_connection=True,
@@ -393,31 +395,46 @@
return all
def classes_from_egg(self, egg_spec):
+ modules = []
+ dist, conf = self.config_from_egg(egg_spec, warn_no_sqlobject=True)
+ for mod in conf.get('db_module', '').split(','):
+ mod = mod.strip()
+ if not mod:
+ continue
+ if self.options.verbose:
+ print 'Looking in module %s' % mod
+ modules.extend(self.classes_from_module(
+ moduleloader.load_module(mod)))
+ return modules
+
+ def load_options_from_egg(self, egg_spec):
+ dist, conf = self.config_from_egg(egg_spec)
+ if (hasattr(self.options, 'output_dir')
+ and not self.options.output_dir
+ and conf.get('history_dir')):
+ dir = conf['history_dir']
+ dir = dir.replace('$base', dist.location)
+ self.options.output_dir = dir
+
+ def config_from_egg(self, egg_spec, warn_no_sqlobject=True):
import pkg_resources
pkg_resources.require(egg_spec)
dist = pkg_resources.working_set.find(pkg_resources.Requirement(egg_spec))
if not dist.has_metadata('sqlobject.txt'):
- print 'No sqlobject.txt in %s' % egg_spec
- return []
- modules = []
- db_module_lines = []
+ if warn_no_sqlobject:
+ print 'No sqlobject.txt in %s egg info' % egg_spec
+ return {}
+ result = {}
for line in dist.get_metadata_lines('sqlobject.txt'):
line = line.strip()
if not line or line.startswith('#'):
continue
name, value = line.split('=', 1)
- if name.strip().lower() == 'db_module':
- db_module_lines.append(value)
- mods = [v.strip() for v in value.split()
- if v.strip()]
- for mod in mods:
- if self.options.verbose:
- print 'Looking in module %s' % mod
- modules.extend(self.classes_from_module(
- moduleloader.load_module(mod)))
- if not db_module_lines:
- print 'No db_module setting in sqlobject.txt'
- return modules
+ name = name.strip().lower()
+ if name in result:
+ print 'Warning: %s appears more than one in sqlobject.txt' % name
+ result[name.strip().lower()] = value.strip()
+ return dist, result
def command(self):
raise NotImplementedError
@@ -937,6 +954,10 @@
base = self.options.output_dir
if base is None:
base = CONFIG.get('sqlobject_history_dir', '.')
+ if not os.path.exists(base):
+ print 'Creating history directory %s' % self.shorten_filename(base)
+ if not self.options.simulate:
+ os.makedirs(base)
return base
def find_output_dir(self):
|
|
From: <sub...@co...> - 2005-09-16 18:49:00
|
Author: test
Date: 2005-09-16 18:48:54 +0000 (Fri, 16 Sep 2005)
New Revision: 992
Modified:
SQLObject/trunk/sqlobject/manager/command.py
Log:
Added --egg loader, which looks for .egg-info/sqlobject.txt
Modified: SQLObject/trunk/sqlobject/manager/command.py
===================================================================
--- SQLObject/trunk/sqlobject/manager/command.py 2005-09-16 17:18:40 UTC (rev 991)
+++ SQLObject/trunk/sqlobject/manager/command.py 2005-09-16 18:48:54 UTC (rev 992)
@@ -155,6 +155,12 @@
metavar="NAME",
dest="class_matchers",
default=[])
+ parser.add_option('--egg',
+ help="Select modules from the given Egg, using sqlobject.txt",
+ action="append",
+ metavar="EGG_SPEC",
+ dest="eggs",
+ default=[])
if interactive:
parser.add_option('-i', '--interactive',
help="Ask before doing anything (use twice to be more careful)",
@@ -219,22 +225,22 @@
conf = self.config()
if conf and conf.get('sys_path'):
update_sys_path(conf['sys_path'], self.options.verbose)
+ if conf and conf.get('database'):
+ conn = sqlobject.connectionForURI(conf['database'])
+ sqlobject.sqlhub.processConnection = conn
self.command()
def classes(self, require_connection=True,
require_some=False):
all = []
conf = self.config()
- if conf and conf.get('database_module'):
- if isinstance(conf['database_module'], (list, tuple)):
- self.options.modules.extend(conf['database_module'])
- else:
- self.options.modules.append(conf['database_module'])
for module_name in self.options.modules:
all.extend(self.classes_from_module(
moduleloader.load_module(module_name)))
for package_name in self.options.packages:
all.extend(self.classes_from_package(package_name))
+ for egg_spec in self.options.eggs:
+ all.extend(self.classes_from_egg(egg_spec))
if self.options.class_matchers:
filtered = []
for soClass in all:
@@ -274,6 +280,10 @@
print 'No packages specified'
if self.options.class_matchers:
print 'Matching class pattern: %s' % self.options.class_matches
+ if self.options.eggs:
+ print 'Looked in eggs: %s' % ', '.join(self.options.eggs)
+ else:
+ print 'No eggs specified'
sys.exit(1)
return all
@@ -354,7 +364,7 @@
def classes_from_package(self, package_name):
all = []
- package = __import__(package_name)
+ package = moduleloader.load_module(package_name)
package_dir = os.path.dirname(package.__file__)
def find_classes_in_file(arg, dir_name, filenames):
@@ -382,6 +392,33 @@
os.path.walk(package_dir, find_classes_in_file, None)
return all
+ def classes_from_egg(self, egg_spec):
+ import pkg_resources
+ pkg_resources.require(egg_spec)
+ dist = pkg_resources.working_set.find(pkg_resources.Requirement(egg_spec))
+ if not dist.has_metadata('sqlobject.txt'):
+ print 'No sqlobject.txt in %s' % egg_spec
+ return []
+ modules = []
+ db_module_lines = []
+ for line in dist.get_metadata_lines('sqlobject.txt'):
+ line = line.strip()
+ if not line or line.startswith('#'):
+ continue
+ name, value = line.split('=', 1)
+ if name.strip().lower() == 'db_module':
+ db_module_lines.append(value)
+ mods = [v.strip() for v in value.split()
+ if v.strip()]
+ for mod in mods:
+ if self.options.verbose:
+ print 'Looking in module %s' % mod
+ modules.extend(self.classes_from_module(
+ moduleloader.load_module(mod)))
+ if not db_module_lines:
+ print 'No db_module setting in sqlobject.txt'
+ return modules
+
def command(self):
raise NotImplementedError
@@ -485,7 +522,10 @@
for soClass in self.classes(require_some=True):
if (self.options.create_db
and soClass._connection not in dbs_created):
- soClass._connection.createEmptyDatabase()
+ if not self.options.simulate:
+ soClass._connection.createEmptyDatabase()
+ else:
+ print '(simulating; cannot create database)'
dbs_created.append(soClass._connection)
exists = soClass._connection.tableExists(soClass.sqlmeta.table)
if v >= 1:
@@ -569,7 +609,7 @@
bad = 0
missing_tables = 0
columnsFromSchema_warning = False
- for soClass in self.classes():
+ for soClass in self.classes(require_some=True):
conn = soClass._connection
self.printed = False
if self.options.verbose:
|
|
From: <sub...@co...> - 2005-09-16 17:18:50
|
Author: test
Date: 2005-09-16 17:18:40 +0000 (Fri, 16 Sep 2005)
New Revision: 991
Modified:
SQLObject/trunk/sqlobject/manager/command.py
Log:
Added package loading support, from Phillipe Normand
Modified: SQLObject/trunk/sqlobject/manager/command.py
===================================================================
--- SQLObject/trunk/sqlobject/manager/command.py 2005-09-15 23:14:33 UTC (rev 990)
+++ SQLObject/trunk/sqlobject/manager/command.py 2005-09-16 17:18:40 UTC (rev 991)
@@ -48,7 +48,8 @@
# to do so.
diffs = []
if not conn.tableExists(soClass.sqlmeta.table):
- diffs.append('Does not exist in database')
+ if soClass.sqlmeta.columns:
+ diffs.append('Does not exist in database')
else:
try:
columns = conn.columnsFromSchema(soClass.sqlmeta.table,
@@ -352,8 +353,35 @@
return config
def classes_from_package(self, package_name):
- raise NotImplementedError
+ all = []
+ package = __import__(package_name)
+ package_dir = os.path.dirname(package.__file__)
+ def find_classes_in_file(arg, dir_name, filenames):
+ if dir_name.startswith('.svn'):
+ return
+ filenames = filter(lambda fname: fname.endswith('.py') and fname != '__init__.py',
+ filenames)
+ for fname in filenames:
+ module_name = os.path.join(dir_name, fname)
+ module_name = module_name[module_name.find(package_name):]
+ module_name = module_name.replace(os.path.sep,'.')[:-3]
+ try:
+ module = moduleloader.load_module(module_name)
+ except ImportError, err:
+ if self.options.verbose:
+ print 'Could not import module "%s". Error was : "%s"' % (module_name, err)
+ continue
+ except Exception, exc:
+ if self.options.verbose:
+ print 'Unknown exception while processing module "%s" : "%s"' % (module_name, exc)
+ continue
+ classes = self.classes_from_module(module)
+ all.extend(classes)
+
+ os.path.walk(package_dir, find_classes_in_file, None)
+ return all
+
def command(self):
raise NotImplementedError
@@ -589,7 +617,6 @@
if self.options.verbose:
print '%i in sync; %i out of sync; %i not in database' % (
good, bad, missing_tables)
-
class CommandHelp(Command):
|
|
From: <sub...@co...> - 2005-09-15 23:14:38
|
Author: test
Date: 2005-09-15 23:14:33 +0000 (Thu, 15 Sep 2005)
New Revision: 990
Modified:
SQLObject/trunk/sqlobject/manager/command.py
Log:
Better error message
Modified: SQLObject/trunk/sqlobject/manager/command.py
===================================================================
--- SQLObject/trunk/sqlobject/manager/command.py 2005-09-13 20:22:39 UTC (rev 989)
+++ SQLObject/trunk/sqlobject/manager/command.py 2005-09-15 23:14:33 UTC (rev 990)
@@ -220,7 +220,8 @@
update_sys_path(conf['sys_path'], self.options.verbose)
self.command()
- def classes(self, require_connection=True):
+ def classes(self, require_connection=True,
+ require_some=False):
all = []
conf = self.config()
if conf and conf.get('database_module'):
@@ -260,6 +261,19 @@
'You must indicate --connection=URI'
% '\n * '.join([soClass.__name__
for soClass in missing]))
+ if require_some and not all:
+ print 'No classes found!'
+ if self.options.modules:
+ print 'Looked in modules: %s' % ', '.join(self.options.modules)
+ else:
+ print 'No modules specified'
+ if self.options.packages:
+ print 'Looked in packages: %s' % ', '.join(self.options.packages)
+ else:
+ print 'No packages specified'
+ if self.options.class_matchers:
+ print 'Matching class pattern: %s' % self.options.class_matches
+ sys.exit(1)
return all
def classes_from_module(self, module):
@@ -440,7 +454,7 @@
created = 0
existing = 0
dbs_created = []
- for soClass in self.classes():
+ for soClass in self.classes(require_some=True):
if (self.options.create_db
and soClass._connection not in dbs_created):
soClass._connection.createEmptyDatabase()
|
|
From: <sub...@co...> - 2005-09-13 20:22:45
|
Author: test Date: 2005-09-13 20:22:39 +0000 (Tue, 13 Sep 2005) New Revision: 989 Modified: SQLObject/trunk/ Log: ez_setup creates a temp/ directory sometimes; ignore it Property changes on: SQLObject/trunk ___________________________________________________________________ Name: svn:ignore - MANIFEST data build dist *.pyc *.pyo *.tmp SQLObject.egg-info + MANIFEST data build dist *.pyc *.pyo *.tmp SQLObject.egg-info temp |
|
From: <sub...@co...> - 2005-09-13 16:31:27
|
Author: phd
Date: 2005-09-13 16:31:22 +0000 (Tue, 13 Sep 2005)
New Revision: 988
Modified:
SQLObject/trunk/sqlobject/main.py
SQLObject/trunk/sqlobject/tests/test_joins.py
Log:
Fixed a problem when Table(foreign_key=value) wouldn't call the foreign_key setter.
Added a test.
Modified: SQLObject/trunk/sqlobject/main.py
===================================================================
--- SQLObject/trunk/sqlobject/main.py 2005-09-13 15:31:09 UTC (rev 987)
+++ SQLObject/trunk/sqlobject/main.py 2005-09-13 16:31:22 UTC (rev 988)
@@ -1188,15 +1188,9 @@
# passed:
for column in self.sqlmeta.columnList:
- # If a foreign key is given, we get the ID of the object
- # and put that in instead
- if kw.has_key(column.foreignName):
- kw[column.name] = getID(kw[column.foreignName])
- del kw[column.foreignName]
-
# Then we check if the column wasn't passed in, and
# if not we try to get the default.
- if not kw.has_key(column.name):
+ if not kw.has_key(column.name) and not kw.has_key(column.foreignName):
default = column.default
# If we don't get it, it's an error:
Modified: SQLObject/trunk/sqlobject/tests/test_joins.py
===================================================================
--- SQLObject/trunk/sqlobject/tests/test_joins.py 2005-09-13 15:31:09 UTC (rev 987)
+++ SQLObject/trunk/sqlobject/tests/test_joins.py 2005-09-13 16:31:22 UTC (rev 988)
@@ -61,6 +61,7 @@
assert hasattr(ExplicitJoiningSO, 'foo')
assert not hasattr(ExplicitJoiningSO, 'bars')
+
class PersonJoiner2(SQLObject):
name = StringCol('name', length=40, alternateID=True)
@@ -105,3 +106,44 @@
assert ([i.zip for i in p1.addressJoiner2s]
== ['33333', '22222', '11111'])
+
+_personJoiner3_getters = []
+_personJoiner3_setters = []
+
+class PersonJoiner3(SQLObject):
+
+ name = StringCol('name', length=40, alternateID=True)
+ addressJoiner3s = MultipleJoin('AddressJoiner3')
+
+class AddressJoiner3(SQLObject):
+
+ zip = StringCol(length=5)
+ personJoiner3 = ForeignKey('PersonJoiner3')
+
+ def _get_personJoiner3(self):
+ value = self._SO_get_personJoiner3()
+ _personJoiner3_getters.append((self, value))
+ return value
+
+ def _set_personJoiner3(self, value):
+ self._SO_set_personJoiner3(value)
+ _personJoiner3_setters.append((self, value))
+
+class TestJoin3:
+
+ def setup_method(self, meth):
+ setupClass([PersonJoiner3, AddressJoiner3])
+ p1 = PersonJoiner3(name='bob')
+ p2 = PersonJoiner3(name='sally')
+ for z in ['11111', '22222', '33333']:
+ a = AddressJoiner3(zip=z, personJoiner3=p1)
+ AddressJoiner3(zip='00000', personJoiner3=p2)
+
+ def test_accessors(self):
+ assert len(_personJoiner3_getters) == 0
+ assert len(_personJoiner3_setters) == 4
+ bob = PersonJoiner3.byName('bob')
+ for addressJoiner3 in bob.addressJoiner3s:
+ addressJoiner3.personJoiner3
+ assert len(_personJoiner3_getters) == 3
+ assert len(_personJoiner3_setters) == 4
|
|
From: <sub...@co...> - 2005-09-13 15:31:19
|
Author: test
Date: 2005-09-13 15:31:09 +0000 (Tue, 13 Sep 2005)
New Revision: 987
Removed:
SQLObject/trunk/sqlobject/tests/test_conngetter.py
Log:
Removed defunct test
Deleted: SQLObject/trunk/sqlobject/tests/test_conngetter.py
===================================================================
--- SQLObject/trunk/sqlobject/tests/test_conngetter.py 2005-09-13 15:25:24 UTC (rev 986)
+++ SQLObject/trunk/sqlobject/tests/test_conngetter.py 2005-09-13 15:31:09 UTC (rev 987)
@@ -1,37 +0,0 @@
-from sqlobject import *
-from sqlobject.tests.dbtest import *
-
-class TestSimple(SQLObject):
-
- class sqlmeta:
- registry = 'conngetter'
-
- name = StringCol(alternateID=True)
-
-class TestJoined(SQLObject):
-
- class sqlmeta:
- registry = 'conngetter'
-
- this_name = StringCol(alternateID=True)
- simple = ForeignKey('TestSimple')
-
-def test_autogetter():
- conn = getConnection(registry='conngetter')
- TestJoined.dropTable(connection=conn, ifExists=True)
- TestSimple.dropTable(connection=conn, ifExists=True)
- TestSimple.createTable(connection=conn, ifNotExists=True)
- TestJoined.createTable(connection=conn, ifNotExists=True)
- assert conn.TestSimple._soClass is TestSimple
- obj = conn.TestSimple(name='test')
- assert (TestSimple.get(obj.id, connection=conn) is obj)
- assert obj._connection is conn
- obj2 = TestSimple(name='test2', connection=conn)
- assert (conn.TestSimple.byName('test2') is obj2)
- joined = conn.TestJoined(this_name='join_test', simple=obj)
- assert joined.simple is obj
- assert joined.simple._connection is conn
- assert joined._connection is conn
- for item in conn.TestSimple.select():
- assert item._connection is conn
-
|
|
From: <sub...@co...> - 2005-09-12 21:12:15
|
Author: test
Date: 2005-09-12 21:12:10 +0000 (Mon, 12 Sep 2005)
New Revision: 985
Modified:
SQLObject/trunk/sqlobject/main.py
Log:
typo
Modified: SQLObject/trunk/sqlobject/main.py
===================================================================
--- SQLObject/trunk/sqlobject/main.py 2005-09-12 21:11:43 UTC (rev 984)
+++ SQLObject/trunk/sqlobject/main.py 2005-09-12 21:12:10 UTC (rev 985)
@@ -618,7 +618,7 @@
error message (better than ``AttributeError``) but where the
feature has been fully removed.
"""
- global warnings_leve, exception_level
+ global warnings_level, exception_level
warnings_level = warning
exception_level = exception
|
|
From: <sub...@co...> - 2005-09-12 21:11:50
|
Author: test
Date: 2005-09-12 21:11:43 +0000 (Mon, 12 Sep 2005)
New Revision: 984
Modified:
SQLObject/trunk/sqlobject/main.py
Log:
Typo and global declaration to fix setDeprecationLevel
Modified: SQLObject/trunk/sqlobject/main.py
===================================================================
--- SQLObject/trunk/sqlobject/main.py 2005-09-12 20:14:50 UTC (rev 983)
+++ SQLObject/trunk/sqlobject/main.py 2005-09-12 21:11:43 UTC (rev 984)
@@ -618,7 +618,8 @@
error message (better than ``AttributeError``) but where the
feature has been fully removed.
"""
- warning_level = warning
+ global warnings_leve, exception_level
+ warnings_level = warning
exception_level = exception
|
|
From: <sub...@co...> - 2005-09-12 08:23:54
|
Author: phd
Date: 2005-09-12 08:23:41 +0000 (Mon, 12 Sep 2005)
New Revision: 978
Modified:
SQLObject/trunk/sqlobject/postgres/pgconnection.py
Log:
Fixed a misspelled "passwd".
Modified: SQLObject/trunk/sqlobject/postgres/pgconnection.py
===================================================================
--- SQLObject/trunk/sqlobject/postgres/pgconnection.py 2005-09-11 05:23:27 UTC (rev 977)
+++ SQLObject/trunk/sqlobject/postgres/pgconnection.py 2005-09-12 08:23:41 UTC (rev 978)
@@ -48,7 +48,7 @@
if user:
dsn_dict["user"] = user
if passwd:
- dsn_dict["password"] = password
+ dsn_dict["password"] = passwd
self.use_dsn = dsn is not None
if dsn is None:
if usePygresql:
|
|
From: <sub...@co...> - 2005-09-07 21:07:22
|
Author: test
Date: 2005-09-07 21:07:18 +0000 (Wed, 07 Sep 2005)
New Revision: 974
Modified:
SQLObject/trunk/sqlobject/manager/command.py
Log:
Allow for ini configuration files (as used by paste.deploy); add --create-db option to create command; read database modules out of config file
Modified: SQLObject/trunk/sqlobject/manager/command.py
===================================================================
--- SQLObject/trunk/sqlobject/manager/command.py 2005-09-07 21:06:29 UTC (rev 973)
+++ SQLObject/trunk/sqlobject/manager/command.py 2005-09-07 21:07:18 UTC (rev 974)
@@ -181,7 +181,7 @@
# This abstract base class
return
register(cls)
-
+
def __init__(self, invoked_as, command_name, args, runner):
self.invoked_as = invoked_as
self.command_name = command_name
@@ -222,6 +222,12 @@
def classes(self, require_connection=True):
all = []
+ conf = self.config()
+ if conf and conf.get('database_module'):
+ if isinstance(conf['database_module'], (list, tuple)):
+ self.options.modules.extend(conf['database_module'])
+ else:
+ self.options.modules.append(conf['database_module'])
for module_name in self.options.modules:
all.extend(self.classes_from_module(
moduleloader.load_module(module_name)))
@@ -285,18 +291,52 @@
return None
def config(self):
- if getattr(self.options, 'config_file', None):
- if not pyconfig:
- print "You must have Python Paste installed (and on your $PYTHONPATH)"
- print "to use the -f/--config-file option."
- sys.exit(2)
+ if not getattr(self.options, 'config_file', None):
+ return None
+ if pyconfig and self.options.config_fn.endswith('.conf'):
config = pyconfig.Config(with_default=True)
config.load(self.options.config_file)
CONFIG.push_process_config(config)
return config
else:
- return None
+ return self.ini_config(self.options.config_file)
+ def ini_config(self, conf_fn):
+ conf_section = 'main'
+ if '#' in conf_fn:
+ conf_fn, conf_section = conf_fn.split('#', 1)
+
+ from ConfigParser import RawConfigParser
+ p = RawConfigParser()
+ # Case-sensitive:
+ p.optionxform = str
+ if not os.path.exists(conf_fn):
+ # Stupid RawConfigParser doesn't give an error for
+ # non-existant files:
+ raise OSError(
+ "Config file %s does not exist" % self.options.config_file)
+ p.read([conf_fn])
+
+ possible_sections = []
+ for section in p.sections():
+ name = section.strip().lower()
+ if conf_section == name or conf_section == name.split(':')[-1]:
+ possible_sections.append(section)
+
+ if not possible_sections:
+ raise OSError(
+ "Config file %s does not have a section [%s] or [*:%s]"
+ % (conf_fn, conf_section, conf_section))
+ if len(possible_sections) > 1:
+ raise OSError(
+ "Config file %s has multiple sections matching %s: %s"
+ % (conf_fn, conf_section, ', '.join(possible_sections)))
+
+ config = {}
+ for op in p.options(possible_sections[0]):
+ config[op] = p.get(possible_sections[0], op)
+ return config
+
def classes_from_package(self, package_name):
raise NotImplementedError
@@ -390,12 +430,21 @@
summary = 'Create tables'
parser = standard_parser(interactive=True)
+ parser.add_option('--create-db',
+ action='store_true',
+ dest='create_db',
+ help="Create the database")
def command(self):
v = self.options.verbose
created = 0
existing = 0
+ dbs_created = []
for soClass in self.classes():
+ if (self.options.create_db
+ and soClass._connection not in dbs_created):
+ soClass._connection.createEmptyDatabase()
+ dbs_created.append(soClass._connection)
exists = soClass._connection.tableExists(soClass.sqlmeta.table)
if v >= 1:
if exists:
@@ -419,8 +468,8 @@
if v >= 1:
print '%i tables created (%i already exist)' % (
created, existing)
+
-
class CommandDrop(Command):
name = 'drop'
@@ -526,8 +575,8 @@
if self.options.verbose:
print '%i in sync; %i out of sync; %i not in database' % (
good, bad, missing_tables)
+
-
class CommandHelp(Command):
name = 'help'
@@ -622,7 +671,7 @@
'database is currently at. Use the upgrade command to '
'sync databases with code.'
% SQLObjectVersionTable.sqlmeta.table)
-
+
parser = standard_parser()
parser.add_option('--output-dir',
help="Base directory for recorded definitions",
@@ -665,7 +714,7 @@
if self.options.force_db_version:
self.command_force_db_version()
return
-
+
v = self.options.verbose
sim = self.options.simulate
classes = self.classes()
@@ -801,7 +850,7 @@
def strip_comments(self, sql):
lines = [l for l in sql.splitlines()
if not l.strip().startswith('--')]
- return '\n'.join(lines)
+ return '\n'.join(lines)
def base_dir(self):
base = self.options.output_dir
@@ -812,7 +861,7 @@
def find_output_dir(self):
today = time.strftime('%Y-%m-%d', time.localtime())
if self.options.version_name:
- dir = os.path.join(self.base_dir(), today + '-' +
+ dir = os.path.join(self.base_dir(), today + '-' +
self.options.version_name)
if os.path.exists(dir):
print ("Error, directory already exists: %s"
@@ -828,7 +877,7 @@
extra = 'a'
else:
extra = chr(ord(extra)+1)
-
+
def find_last_version(self):
names = []
for fn in os.listdir(self.base_dir()):
@@ -921,6 +970,7 @@
raise
self.update_db(next_version, conn)
print 'Done.'
+
def current_version(self):
conn = self.connection()
@@ -981,8 +1031,8 @@
print 'No upgraders found in %s' % current_dir
return None, None
upgraders.sort()
- return upgraders[-1]
-
+ return upgraders[-1]
+
def update_sys_path(paths, verbose):
if isinstance(paths, (str, unicode)):
paths = [paths]
|
|
From: <sub...@co...> - 2005-09-07 21:06:34
|
Author: test
Date: 2005-09-07 21:06:29 +0000 (Wed, 07 Sep 2005)
New Revision: 973
Modified:
SQLObject/trunk/sqlobject/dbconnection.py
SQLObject/trunk/sqlobject/postgres/pgconnection.py
Log:
Add conn.createEmptyDatabase() method, plus an implementation for Postgres
Modified: SQLObject/trunk/sqlobject/dbconnection.py
===================================================================
--- SQLObject/trunk/sqlobject/dbconnection.py 2005-09-07 21:05:48 UTC (rev 972)
+++ SQLObject/trunk/sqlobject/dbconnection.py 2005-09-07 21:06:29 UTC (rev 973)
@@ -667,6 +667,12 @@
finally:
self._poolLock.release()
+ def createEmptyDatabase(self):
+ """
+ Create an empty database.
+ """
+ raise NotImplementedError
+
class Iteration(object):
def __init__(self, dbconn, rawconn, select, keepConnection=False):
Modified: SQLObject/trunk/sqlobject/postgres/pgconnection.py
===================================================================
--- SQLObject/trunk/sqlobject/postgres/pgconnection.py 2005-09-07 21:05:48 UTC (rev 972)
+++ SQLObject/trunk/sqlobject/postgres/pgconnection.py 2005-09-07 21:06:29 UTC (rev 973)
@@ -16,6 +16,7 @@
user=None, passwd=None, usePygresql=False,
**kw):
global psycopg, pgdb
+ self.usePygresql = usePygresql
if usePygresql:
if pgdb is None:
import pgdb
@@ -278,7 +279,35 @@
return self._server_version
server_version = property(server_version)
+ def createEmptyDatabase(self):
+ # We have to connect to *some* database, so we'll connect to
+ # template1, which is a common open database.
+ # @@: This doesn't use self.use_dsn or self.dsn_dict
+ if self.usePygresql:
+ dsn = '%s:template1:%s:%s' % (
+ self.host or '', self.user or '', self.password or '')
+ else:
+ dsn = 'dbname=template1'
+ if self.user:
+ dsn += ' user=%s' % self.user
+ if self.password:
+ dsn += ' passwd=%s' % self.passwd
+ if self.host:
+ dsn += ' host=%s' % self.host
+ conn = self.module.connect(dsn)
+ cur = conn.cursor()
+ # We must close the transaction with a commit so that
+ # the CREATE DATABASE can work (which can't be in a transaction):
+ cur.execute('COMMIT')
+ # And we can't use template1 since we're connected to template1,
+ # so we use template0. @@: What's the difference between
+ # these two templates?
+ cur.execute('CREATE DATABASE %s TEMPLATE=template0' % self.db)
+ cur.close()
+ conn.close()
+
+
# Converter for psycopg Binary type.
def PsycoBinaryConverter(value, db):
assert db == 'postgres'
|
|
From: <sub...@co...> - 2005-09-07 21:05:59
|
Author: test
Date: 2005-09-07 21:05:48 +0000 (Wed, 07 Sep 2005)
New Revision: 972
Modified:
SQLObject/trunk/scripts/sqlobject-admin
Log:
Make it more permissive about versions (I don't konw why it's being picky)
Modified: SQLObject/trunk/scripts/sqlobject-admin
===================================================================
--- SQLObject/trunk/scripts/sqlobject-admin 2005-09-07 14:43:45 UTC (rev 971)
+++ SQLObject/trunk/scripts/sqlobject-admin 2005-09-07 21:05:48 UTC (rev 972)
@@ -4,7 +4,7 @@
try:
import pkg_resources
- pkg_resources.require('SQLObject>=0.7dev')
+ pkg_resources.require('SQLObject>0.6.1')
except (ImportError, pkg_resources.DistributionNotFound):
# Oh well, we tried...
pass
|
|
From: <sub...@co...> - 2005-09-07 14:43:53
|
Author: phd
Date: 2005-09-07 14:43:45 +0000 (Wed, 07 Sep 2005)
New Revision: 971
Modified:
SQLObject/trunk/sqlobject/sqlbuilder.py
Log:
Allow an SQL identifier to be started with an underscore.
Modified: SQLObject/trunk/sqlobject/sqlbuilder.py
===================================================================
--- SQLObject/trunk/sqlobject/sqlbuilder.py 2005-09-02 15:53:50 UTC (rev 970)
+++ SQLObject/trunk/sqlobject/sqlbuilder.py 2005-09-07 14:43:45 UTC (rev 971)
@@ -72,7 +72,7 @@
import threading
from converters import sqlrepr, registerConverter, TRUE, FALSE
-safeSQLRE = re.compile(r'^[a-zA-Z][a-zA-Z0-9_\.]*$')
+safeSQLRE = re.compile(r'^[a-zA-Z_][a-zA-Z0-9_\.]*$')
def sqlIdentifier(obj):
return type(obj) is type("") and not not safeSQLRE.search(obj.strip())
|
|
From: <sub...@co...> - 2005-09-01 16:24:56
|
Author: phd
Date: 2005-09-01 16:24:50 +0000 (Thu, 01 Sep 2005)
New Revision: 969
Modified:
SQLObject/trunk/docs/Inheritance.txt
Log:
Minor documentation update.
Modified: SQLObject/trunk/docs/Inheritance.txt
===================================================================
--- SQLObject/trunk/docs/Inheritance.txt 2005-09-01 16:00:50 UTC (rev 968)
+++ SQLObject/trunk/docs/Inheritance.txt 2005-09-01 16:24:50 UTC (rev 969)
@@ -21,7 +21,7 @@
The following code::
- frim sqlobject.inheritance import InheritableSQLObject
+ from sqlobject.inheritance import InheritableSQLObject
class Person(InheritableSQLObject):
firstName = StringCol()
lastName = StringCol()
@@ -54,11 +54,11 @@
child ID as they are the same.
The column childName will contain the name of the child class (for
-exemple 'Employee'). This will permit to a class to always return its
+example 'Employee'). This will permit to a class to always return its
child class if available (a person that is also an employee will always
return an instance of the employee class).
-For exemple, the following code::
+For example, the following code::
p = Person(firstName='John', lastName='Doe')
e = Employee(firstName='Jane', lastName='Doe', position='Chief')
@@ -122,7 +122,7 @@
* Only simple inheritance will work. It is not possible to inherit
from multiple SQLObject classes.
* It is possible to inherit from an inherited class and this will
- work well. In the above exemple, you can have a Chief class that
+ work well. In the above example, you can have a Chief class that
inherits from Employee and all parents attributes will be
available through the Chief class.
* You may not redefine columns in an inherited class (this
@@ -130,6 +130,10 @@
* If you don't want 'childName' columns in your last class (one that
will never be inherited), you must set '_inheritable' to False in this
class.
+* The inheritance implementation is incompatible with lazy updates. Do not
+ set lazyUpdate to True. If you need this - you have to patch SQLObject
+ and override many methods - _SO_setValue(), sync(), syncUpdate() at
+ least. Patches will be gladly accepted.
* I made it because I needed to be able to have automatic
inheritance with linked table.
* This version works for me, it may not works for you. I tried to do
|
|
From: <sub...@co...> - 2005-09-01 16:00:58
|
Author: phd
Date: 2005-09-01 16:00:50 +0000 (Thu, 01 Sep 2005)
New Revision: 968
Modified:
SQLObject/trunk/sqlobject/dbconnection.py
Log:
Minor enhabcement by Benjamin Yu <ben...@in...> to make
connection pool more like queue rather than a stack.
Modified: SQLObject/trunk/sqlobject/dbconnection.py
===================================================================
--- SQLObject/trunk/sqlobject/dbconnection.py 2005-08-30 15:55:11 UTC (rev 967)
+++ SQLObject/trunk/sqlobject/dbconnection.py 2005-09-01 16:00:50 UTC (rev 968)
@@ -268,7 +268,7 @@
# @@: We can get duplicate releasing of connections with
# the __del__ in Iteration (unfortunately, not sure why
# it happens)
- self._pool.append(conn)
+ self._pool.insert(0, conn)
else:
conn.close()
|
|
From: <sub...@co...> - 2005-08-30 15:55:18
|
Author: phd
Date: 2005-08-30 15:55:11 +0000 (Tue, 30 Aug 2005)
New Revision: 967
Modified:
SQLObject/trunk/sqlobject/inheritance/__init__.py
Log:
Fixed a minor bug (I havn't fully synchronized with sqlmeta).
Modified: SQLObject/trunk/sqlobject/inheritance/__init__.py
===================================================================
--- SQLObject/trunk/sqlobject/inheritance/__init__.py 2005-08-30 09:11:57 UTC (rev 966)
+++ SQLObject/trunk/sqlobject/inheritance/__init__.py 2005-08-30 15:55:11 UTC (rev 967)
@@ -113,8 +113,7 @@
#DSM: Only do this once if possible at object creation and once for
#DSM: each new dynamic join to refresh the current class
if childUpdate or soClass._parentClass:
- for jdef in soClass._parentClass.sqlmeta.joins:
- join = jdef.withClass(soClass)
+ for join in soClass._parentClass.sqlmeta.joins:
jname = join.joinMethodName
jarn = join.addRemoveName
setattr(soClass, getterName(jname),
|
|
From: <sub...@co...> - 2005-08-30 09:12:11
|
Author: phd
Date: 2005-08-30 09:11:57 +0000 (Tue, 30 Aug 2005)
New Revision: 966
Modified:
SQLObject/trunk/sqlobject/postgres/pgconnection.py
Log:
Fixed a bug - use port to conect to the database.
Modified: SQLObject/trunk/sqlobject/postgres/pgconnection.py
===================================================================
--- SQLObject/trunk/sqlobject/postgres/pgconnection.py 2005-08-29 01:53:15 UTC (rev 965)
+++ SQLObject/trunk/sqlobject/postgres/pgconnection.py 2005-08-30 09:11:57 UTC (rev 966)
@@ -34,6 +34,21 @@
self.port = port
self.db = db
self.password = passwd
+ self.dsn_dict = dsn_dict = {}
+ if host:
+ dsn_dict["host"] = host
+ if port:
+ if usePygresql:
+ dsn_dict["host"] = "%s:%d" % (host, port)
+ else:
+ dsn_dict["port"] = str(port)
+ if db:
+ dsn_dict["database"] = db
+ if user:
+ dsn_dict["user"] = user
+ if passwd:
+ dsn_dict["password"] = password
+ self.use_dsn = dsn is not None
if dsn is None:
if usePygresql:
dsn = ''
@@ -57,8 +72,9 @@
if passwd:
dsn.append('password=%s' % passwd)
if host:
- # @@: right format?
dsn.append('host=%s' % host)
+ if port:
+ dsn.append('port=%d' % port)
dsn = ' '.join(dsn)
self.dsn = dsn
DBAPI.__init__(self, **kw)
@@ -79,7 +95,10 @@
def makeConnection(self):
try:
- conn = self.module.connect(self.dsn)
+ if self.use_dsn:
+ conn = self.module.connect(self.dsn)
+ else:
+ conn = self.module.connect(**self.dsn_dict)
except self.module.OperationalError, e:
raise self.module.OperationalError("%s; used connection string %r" % (e, self.dsn))
if self.autoCommit:
|