well, I found this one.
http://www.eflorenzano.com/blog/post/database-triggers-arent-evil-and-they-actually-kin/

I've tried to implement something like that in mysql with my model but I get
this error:

_mysql_exceptions.ProgrammingError: (2014, "Commands out of sync; you can't
run this command now")

this is my implementation:

from django.db.models import signals
from ucp.panel import models

sql = """

DROP TRIGGER IF EXISTS new_domain;
CREATE TRIGGER new_domain BEFORE INSERT ON panel_domain
FOR EACH ROW
BEGIN
 DECLARE service integer;
IF ( NEW.hosted ) THEN
SET @domain = SUBSTRING(LCASE(NEW.name),'.',-1);
 SET @domain = CONCAT('domain',@domain);
SELECT service_id INTO service FROM panel_service WHERE
specific_da...@domain;
 INSERT INTO panel_order (service, member, description, included, discount,
discharge_date, cessation_date)
VALUES(@service,NEW.member_id,NEW.name,0,0,CURTIME(),CURTIME());
 END IF;
END;

"""

def create_trigger(app, created_models, verbosity, **kwargs):
    from django.db import connection
    cursor = connection.cursor()
    cursor.execute(sql)
signals.post_syncdb.connect(create_trigger, sender=models)


any idea¿¿

thanks!
Marc.


Traceback (most recent call last):
  File "manage.py", line 11, in <module>
    execute_manager(settings)
  File "/usr/lib/pymodules/python2.6/django/core/management/__init__.py",
line 362, in execute_manager
    utility.execute()
  File "/usr/lib/pymodules/python2.6/django/core/management/__init__.py",
line 303, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/lib/pymodules/python2.6/django/core/management/base.py", line
195, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/usr/lib/pymodules/python2.6/django/core/management/base.py", line
222, in execute
    output = self.handle(*args, **options)
  File "/usr/lib/pymodules/python2.6/django/core/management/base.py", line
351, in handle
    return self.handle_noargs(**options)
  File
"/usr/lib/pymodules/python2.6/django/core/management/commands/syncdb.py",
line 99, in handle_noargs
    emit_post_sync_signal(created_models, verbosity, interactive)
  File "/usr/lib/pymodules/python2.6/django/core/management/sql.py", line
205, in emit_post_sync_signal
    interactive=interactive)
  File "/usr/lib/pymodules/python2.6/django/dispatch/dispatcher.py", line
166, in send
    response = receiver(signal=self, sender=sender, **named)
  File "/var/www/ucp/../ucp/panel/management.py", line 24, in create_trigger
    cursor.execute(sql)
  File "/usr/lib/pymodules/python2.6/django/db/backends/util.py", line 19,
in execute
    return self.cursor.execute(sql, params)
  File "/usr/lib/pymodules/python2.6/django/db/backends/mysql/base.py", line
84, in execute
    return self.cursor.execute(query, args)
  File "/usr/lib/pymodules/python2.6/MySQLdb/cursors.py", line 168, in
execute
    if not self._defer_warnings: self._warning_check()
  File "/usr/lib/pymodules/python2.6/MySQLdb/cursors.py", line 75, in
_warning_check
    warnings = self._get_db().show_warnings()
  File "/usr/lib/pymodules/python2.6/MySQLdb/connections.py", line 300, in
show_warnings
    self.query("SHOW WARNINGS")
_mysql_exceptions.ProgrammingError: (2014, "Commands out of sync; you can't
run this command now")


On Tue, Dec 29, 2009 at 2:49 AM, Marc Aymerich <glicer...@gmail.com> wrote:

> Hello,
> Is possible to implement mysql triggers with django?? there are some
> documentation about it?
>
> Thanks!!
> Marc
>

--

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


Reply via email to