Re: [Django] #1946: [patch] to allow overriding of default sequence name

2011-03-26 Thread Django
#1946: [patch] to allow overriding of default sequence name
-+-
   Reporter:  abuse@…|Owner:  shmengie
 Status:  assigned   |Milestone:
  Component:  Database   |  Version:
  layer (models, ORM)| Keywords:
 Resolution: |Has patch:  1
   Triage Stage:  Accepted   |  Needs tests:  1
Needs documentation:  1  |
Patch needs improvement:  1  |
-+-
Changes (by maxi):

 * cc: maxirobaina@… (added)


-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



Re: [Django] #1946: [patch] to allow overriding of default sequence name

2011-03-13 Thread Django
#1946: [patch] to allow overriding of default sequence name
-+-
   Reporter:  abuse@…|Owner:  shmengie
 Status:  assigned   |Milestone:
  Component:  Database   |  Version:
  layer (models, ORM)| Keywords:
 Resolution: |Has patch:  1
   Triage Stage:  Accepted   |  Needs tests:  1
Needs documentation:  1  |
Patch needs improvement:  1  |
-+-

Comment (by HM):

 Partially fixed by #8901.

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



Re: [Django] #1946: [patch] to allow overriding of default sequence name

2010-10-07 Thread Django
#1946: [patch] to allow overriding of default sequence name
---+
  Reporter:  ab...@cabal.org.uk| Owner:  shmengie
Status:  assigned  | Milestone:  
 Component:  Database layer (models, ORM)  |   Version:  
Resolution:|  Keywords:  
 Stage:  Accepted  | Has_patch:  1   
Needs_docs:  1 |   Needs_tests:  1   
Needs_better_patch:  1 |  
---+
Changes (by anonymous):

 * cc: boton...@gmail.com (added)

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



Re: [Django] #1946: [patch] to allow overriding of default sequence name

2009-09-03 Thread Django
#1946: [patch] to allow overriding of default sequence name
---+
  Reporter:  ab...@cabal.org.uk| Owner:  shmengie
Status:  assigned  | Milestone:  
 Component:  Database layer (models, ORM)  |   Version:  
Resolution:|  Keywords:  
 Stage:  Accepted  | Has_patch:  1   
Needs_docs:  1 |   Needs_tests:  1   
Needs_better_patch:  1 |  
---+
Changes (by ernst):

 * cc: er...@stickybit.se (added)

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~--~~~~--~~--~--~---



Re: [Django] #1946: [patch] to allow overriding of default sequence name

2009-08-23 Thread Django
#1946: [patch] to allow overriding of default sequence name
---+
  Reporter:  ab...@cabal.org.uk| Owner:  shmengie
Status:  assigned  | Milestone:  
 Component:  Database layer (models, ORM)  |   Version:  
Resolution:|  Keywords:  
 Stage:  Accepted  | Has_patch:  1   
Needs_docs:  1 |   Needs_tests:  1   
Needs_better_patch:  1 |  
---+
Changes (by shmengie):

  * owner:  nobody => shmengie
  * status:  new => assigned

Comment:

 HM I like the elegance of your solution, but the potential performance
 repercussion will likely keep it out of the codebase.

 The Meta.sequence_name = 'my_cust_seq' has minimal performance impact (one
 python if statement) per InsertQuery.  Legacy integrators will not be
 concerned with table creation, but will appreciate being able to integrate
 their schema into django.  The Meta.sequence_name would need to be
 documented.

 Pros:
   Eases legacy integration
   Adds feature custom sequence_name ability

 Cons:
   Does not address sequence creation issues
   minimal performance impact (more a pro than con)
   minimal additional code in base

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~--~~~~--~~--~--~---



Re: [Django] #1946: [patch] to allow overriding of default sequence name

2009-08-21 Thread Django
#1946: [patch] to allow overriding of default sequence name
---+
  Reporter:  ab...@cabal.org.uk| Owner:  nobody
Status:  new   | Milestone:
 Component:  Database layer (models, ORM)  |   Version:
Resolution:|  Keywords:
 Stage:  Accepted  | Has_patch:  1 
Needs_docs:  1 |   Needs_tests:  1 
Needs_better_patch:  1 |  
---+
Comment (by HM):

 I wound up making my own postgres-backend (based on psycopg2) that asks
 postgres itself what the sequence is, recursively:

 {{{
 # introspection.py

 from django.db.backends.postgresql_psycopg2.base import DatabaseOperations
 from django.db.backends.postgresql_psycopg2.introspection import *
 from psycopg2 import ProgrammingError

 def quote_name(name):
 if name.startswith('"') and name.endswith('"'):
 return name # Quoting once is enough.
 return '"%s"' % name

 def _get_direct_sequence_name(cursor, table_name, pk_name):
 "Fetch the sequence name of an auto-incrementing field, if any"
 table_name = quote_name(table_name)
 cursor.execute('''SELECT * FROM pg_get_serial_sequence(%s, %s);''',
 (table_name, pk_name))
 return cursor.fetchone()[0]

 def get_sequence_name(cursor, table_name, pk_name, level=1):
 "Fetch the sequence name of an auto-incrementing field, if any, also
 tries parents"
 try:
 seq_name = _get_direct_sequence_name(cursor, table_name, pk_name)
 if not seq_name:
 raise ProgrammingError, "Table '%s' had no direct sequence-
 name" % table_name
 return seq_name
 except ProgrammingError, e:
 cursor.execute('SELECT parent.relname '
 'FROM pg_inherits i '
 'INNER JOIN pg_class parent ON parent.oid = i.inhparent '
 'INNER JOIN pg_class child ON child.oid = i.inhrelid '
 'WHERE child.relname = %s ORDER BY i.inhseqno;',
 (table_name,))
 if cursor.rowcount < 1 or cursor.rowcount is None:
 raise ProgrammingError, 'No sequence found for pk %s of table
 %s or parents of table %s' % (pk_name, table_name, table_name)
 # This is safe as the number of rows returned usually will be very
 few
 rows = [str(row[0]) for row in cursor.fetchall()]
 for parent in rows:
 seq_name = _get_direct_sequence_name(cursor, parent, pk_name)
 if seq_name:
 return seq_name.split('.')[1]
 # XXX: level (recursion-depth) should be a setting?
 if level < 3:
 return get_sequence_name(cursor, parent, pk_name, level+1)
 return None
 }}}

 I think the below is the minimum needed in base.py:

 {{{
 # base.py

 # lots of imports here, look at
 django.db.backends.postgresql_psycopg2.base

 class DatabaseOperations(PostgresqlDatabaseOperations):

 def last_insert_id(self, cursor, table_name, pk_name):
 "Try fetching existing sequence, else generate as per standard
 django"
 seq_name = get_sequence_name(cursor, table_name, pk_name)
 if seq_name is None:
 seq_name = "%s_%s_seq" % (table_name, pk_name)
 cursor.execute("SELECT CURRVAL(%s)", (seq_name,))
 return cursor.fetchone()[0]

 class DatabaseWrapper(BaseDatabaseWrapper):
 def __init__(self, *args, **kwargs):
 super(DatabaseWrapper, self).__init__(*args, **kwargs)
 self.ops = DatabaseOperations()
 }}}

 The annoyances with this solution is of course that it is slower than
 hardcoded sequence-names and that it has to be deployed with django, as a
 dir in django/db/backends/.

 Now, a system that fetched the sequence-names during model-import and
 stored them in the models, that would maybe be the best solution (for a
 legacy database like what I'm working with anyway).

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~--~~~~--~~--~--~---



Re: [Django] #1946: [patch] to allow overriding of default sequence name

2009-08-20 Thread Django
#1946: [patch] to allow overriding of default sequence name
---+
  Reporter:  ab...@cabal.org.uk| Owner:  nobody
Status:  new   | Milestone:
 Component:  Database layer (models, ORM)  |   Version:
Resolution:|  Keywords:
 Stage:  Accepted  | Has_patch:  1 
Needs_docs:  1 |   Needs_tests:  1 
Needs_better_patch:  1 |  
---+
Comment (by 1st...@gmail.com):

 I chose to take a slightly different approach to this issue, which seems a
 less intrusive alternative.  It limited to one sequence per table, but I
 doubt that's an issue.

 In db/models/options.py:
 Added property 'sequence_name'

 In postgresql/operations.py
 def sequence_currval(self, cursor, sequence):
 cursor.execute("SELECT CURRVAL('\"%s\"')" % (sequence,))
 return cursor.fetchone()[0]

 models/sql/InsertQuery.execute_sql() # last if before catch-all return
 if self.model._meta.sequence_name:
 return self.connection.ops.sequence_currval(
 cursor, self.model._meta.sequence_name)

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~--~~~~--~~--~--~---



Re: [Django] #1946: [patch] to allow overriding of default sequence name

2009-08-20 Thread Django
#1946: [patch] to allow overriding of default sequence name
---+
  Reporter:  ab...@cabal.org.uk| Owner:  nobody
Status:  new   | Milestone:
 Component:  Database layer (models, ORM)  |   Version:
Resolution:|  Keywords:
 Stage:  Accepted  | Has_patch:  1 
Needs_docs:  1 |   Needs_tests:  1 
Needs_better_patch:  1 |  
---+
Comment (by anonymous):

 Is there any chance this patch can be integrated into the core?

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~--~~~~--~~--~--~---



Re: [Django] #1946: [patch] to allow overriding of default sequence name

2009-01-08 Thread Django
#1946: [patch] to allow overriding of default sequence name
---+
  Reporter:  ab...@cabal.org.uk| Owner:  nobody
Status:  new   | Milestone:
 Component:  Database layer (models, ORM)  |   Version:
Resolution:|  Keywords:
 Stage:  Accepted  | Has_patch:  1 
Needs_docs:  1 |   Needs_tests:  1 
Needs_better_patch:  1 |  
---+
Comment (by mtredinnick):

 For anybody working to bring this to conclusion, a few notes from some
 discussions Rob Hudson and I have had about this:

 There are three separate sub-problems that probably need to be addressed.
  1. Manually specifying the sequence name to use.
  2. Specifying that `ModelA` should use the same sequence name as `ModelB`
  3. Perhaps: somehow creating the sequence for case 1.

 It's not necessarily compulsory that all are solved, and the original
 problem description only looks at situation 1, from what I understand. The
 difficulty there is when does this sequence we are referring to by name
 get created? It can't be as part of "initial SQL" processing or
 post_syncdb signal handling, since that's after the table has been created
 and, presumably, the sequence has to exist before you can refer to it in a
 table definition. Maybe that's completely out of scope (quite possibly).
 If not, it's situation 3. Solving that certainly makes testing a lot
 easier (might well move it from "impossible" into the "possible"
 category).

 The second point, above, seems to be something that might crop up quite
 naturally here. If you want to share a sequence for some reason, you need
 to indicate that, but you don't actually know the name of the sequence.
 Again, maybe out of scope, although it would be nice if it were possible.

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~--~~~~--~~--~--~---



Re: [Django] #1946: [patch] to allow overriding of default sequence name

2008-12-15 Thread Django
#1946: [patch] to allow overriding of default sequence name
---+
  Reporter:  ab...@cabal.org.uk| Owner:  nobody
Status:  new   | Milestone:
 Component:  Database layer (models, ORM)  |   Version:
Resolution:|  Keywords:
 Stage:  Accepted  | Has_patch:  1 
Needs_docs:  1 |   Needs_tests:  1 
Needs_better_patch:  1 |  
---+
Changes (by mmoedt):

 * cc: mmo...@gmail.com (added)

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~--~~~~--~~--~--~---



Re: [Django] #1946: [patch] to allow overriding of default sequence name

2008-12-11 Thread Django
#1946: [patch] to allow overriding of default sequence name
---+
  Reporter:  ab...@cabal.org.uk| Owner:  nobody
Status:  new   | Milestone:
 Component:  Database layer (models, ORM)  |   Version:
Resolution:|  Keywords:
 Stage:  Accepted  | Has_patch:  1 
Needs_docs:  1 |   Needs_tests:  1 
Needs_better_patch:  1 |  
---+
Changes (by robhudson):

 * cc: treborhud...@gmail.com (added)

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~--~~~~--~~--~--~---



Re: [Django] #1946: [patch] to allow overriding of default sequence name

2007-01-02 Thread Django

#1946: [patch] to allow overriding of default sequence name
+---
Reporter:  [EMAIL PROTECTED]  |Owner:  adrian
Type:  enhancement |   Status:  new   
Priority:  normal  |Milestone:
Component:  Database wrapper|  Version:
Severity:  normal  |   Resolution:
Keywords:  |  
+---

Changes (by anonymous):

* cc: [EMAIL PROTECTED] (added)

Comment:



--
Ticket URL: 
Django 
The web framework for perfectionists with deadlines.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Django 
updates" group.
To post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~--~~~~--~~--~--~---



Re: [Django] #1946: [PATCH] to allow overriding of default sequence name

2006-06-03 Thread Django
#1946: [PATCH] to allow overriding of default sequence name
+---
 Reporter:  [EMAIL PROTECTED]  |Owner:  adrian
 Type:  enhancement |   Status:  new   
 Priority:  normal  |Milestone:
Component:  Database wrapper|  Version:
 Severity:  normal  |   Resolution:
 Keywords:  |  
+---
Comment (by nirvdrum):

 Another use case is integrating with legacy databases.  I just found out I
 can't really use auto-increment IDs with django until something like this
 patch gets integrated because the legacy sequence names are not what
 django expects.

-- 
Ticket URL: 
Django 
The web framework for perfectionists with deadlines.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates
-~--~~~~--~~--~--~---



[Django] #1946: [PATCH] to allow overriding of default sequence name

2006-05-20 Thread Django
#1946: [PATCH] to allow overriding of default sequence name
+---
 Reporter:  [EMAIL PROTECTED]  |   Owner:  adrian
 Type:  enhancement |  Status:  new   
 Priority:  normal  |   Milestone:
Component:  Database wrapper| Version:
 Severity:  normal  |Keywords:
+---
 I wanted to be able to use Django's admin interface to edit PostgreSQL
 inherited tables. The normal use would be to have a single sequence on the
 parent table and let the children inherit that, so that the IDs across all
 children are unique. However, Django assumes that the sequence name is
 tablename_columnname_seq which does not apply in this case.
 
 I have created the folloiwing patch to allow one to override the default
 sequence name with one of your choosing by adding a seq_name= parameter
 when defining the field, like this:
 
 {{{
 class PeerIAX(models.Model):
 class Admin: pass
 id = models.AutoField(primary_key=True,
 seq_name='asterisk_peer_id_seq')
 description = models.CharField(maxlength=255)
 hostname = models.CharField(maxlength=255)
 username = models.CharField(maxlength=255)
 secret = models.CharField(maxlength=255)
 def __str__(self):
 return description
 }}}
 
 In case it's not obvious, this simple patch does not add support to Django
 to actually *create* the tables. I hand-created them like so:
 
 {{{
 CREATE TABLE asterisk_peer (
 id  SERIAL  NOT NULL PRIMARY KEY,
 description VARCHAR(255)NOT NULL
 );
 
 CREATE TABLE asterisk_peer_iax (
 hostnameVARCHAR(255)NOT NULL,
 usernameVARCHAR(255)NOT NULL,
 secret  VARCHAR(255)NOT NULL
 ) INHERITS (asterisk_peer);
 }}}
 
 The patch is below. I abandon copyright on the code and you are welcome to
 incorporate the patch into Django as you see fit.
 
 {{{
 diff -rduP ../Django-0.91-
 py2.3.egg.orig/django/db/backends/ado_mssql/base.py
 ./django/db/backends/ado_mssql/base.py
 --- ../Django-0.91-py2.3.egg.orig/django/db/backends/ado_mssql/base.py
 2006-05-15 13:52:49.0 +0100
 +++ ./django/db/backends/ado_mssql/base.py  2006-05-20
 20:09:24.0 +0100
 @@ -94,7 +94,9 @@
  dictfetchmany = util.dictfetchmany
  dictfetchall  = util.dictfetchall
 
 -def get_last_insert_id(cursor, table_name, pk_name):
 +def get_last_insert_id(cursor, table_name, pk_name, seq_name):
 +# FIXME: seq_name might be a useful thing to add to backends other
 than
 +# PostgreSQL
  cursor.execute("SELECT %s FROM %s WHERE %s = @@IDENTITY" % (pk_name,
 table_name, pk_name))
  return cursor.fetchone()[0]
 
 diff -rduP ../Django-0.91-py2.3.egg.orig/django/db/backends/mysql/base.py
 ./django/db/backends/mysql/base.py
 --- ../Django-0.91-py2.3.egg.orig/django/db/backends/mysql/base.py
 2006-05-15 13:52:49.0 +0100
 +++ ./django/db/backends/mysql/base.py  2006-05-20 20:10:01.0
 +0100
 @@ -117,7 +117,9 @@
  dictfetchmany = util.dictfetchmany
  dictfetchall  = util.dictfetchall
 
 -def get_last_insert_id(cursor, table_name, pk_name):
 +def get_last_insert_id(cursor, table_name, pk_name, seq_name):
 +# FIXME: seq_name might be a useful thing to add to backends other
 than
 +# PostgreSQL
  return cursor.lastrowid
 
  def get_date_extract_sql(lookup_type, table_name):
 diff -rduP ../Django-0.91-
 py2.3.egg.orig/django/db/backends/postgresql/base.py
 ./django/db/backends/postgresql/base.py
 --- ../Django-0.91-py2.3.egg.orig/django/db/backends/postgresql/base.py
 2006-05-15 13:52:49.0 +0100
 +++ ./django/db/backends/postgresql/base.py 2006-05-20
 19:40:12.0 +0100
 @@ -75,8 +75,10 @@
  "Returns all rows from a cursor as a dict"
  return cursor.dictfetchall()
 
 -def get_last_insert_id(cursor, table_name, pk_name):
 -cursor.execute("SELECT CURRVAL('\"%s_%s_seq\"')" % (table_name,
 pk_name))
 +def get_last_insert_id(cursor, table_name, pk_name, seq_name):
 +if seq_name is None:
 +seq_name = "%s_%s_seq" % (table_name, pk_name)
 +cursor.execute("SELECT CURRVAL('\"%s\"')" % seq_name)
  return cursor.fetchone()[0]
 
  def get_date_extract_sql(lookup_type, table_name):
 diff -rduP ../Django-0.91-
 py2.3.egg.orig/django/db/backends/sqlite3/base.py
 ./django/db/backends/sqlite3/base.py
 --- ../Django-0.91-py2.3.egg.orig/django/db/backends/sqlite3/base.py
 2006-05-15 13:52:49.0 +0100
 +++ ./django/db/backends/sqlite3/base.py2006-05-20
 20:10:11.0 +0100
 @@ -90,7 +90,9 @@
  dictfetchmany = util.dictfetchmany
  dictfetchall  = util.dictfetchall
 
 -def get_last_insert_id(cursor, table_name, pk_name):
 +def get_last_insert_id(cursor, table_name, pk_name, seq_name):
 +# FIXME: seq_name might be a useful thing to add to backends other
 than
 +# P