Rory Campbell-Lange wrote:
> Dear Developers
> 
> The error:
> 
> INSERT INTO "data_sector" 
>             ("name","localname","created","modified","country_id") 
>        VALUES 
>             (Administrative Offices,'','2006-11-18 
> 21:36:31.145400','2006-11-18 21:36:31.145474',1)
> 
> 'Administrative Offices' isn't quoted. I believe this is because the
> 'Administrative Offices' string is a unicode string (u'Ad...') and that
> the psycopg module can't handle unicode strings.

yes, it's a bug in psycopg1. it does not escape unicode strings.
it should probable be solved by the django-layer, but it's planned to 
switch django completely to unicode, so this issue will probably be 
solved that time.
> 
> This is a problem reported in bug #305. I am using the work-around
> provided in that report to encode unicode strings to utf-8, but it seems
> inelegant.
> 
> I've installed psycopg2, as I believe this does not suffer from this
> issue. However I cannot find a straightforward way of setting django to
> use psycopg2.


DATABASE_ENGINE = 'postgresql_psycopg2'

gabor

> 
> Thanks for any help;
> Rory
> 
> 
> Background:
> 
> data.models.Sector definitions:
> 
> class Sector (models.Model, General):
>     name      = models.CharField('Project Sector Name', blank = False, 
> maxlength = 200)
>     localname = models.CharField('Local Sector Name'  , blank = False, 
> maxlength = 200)
>     created   = models.DateTimeField(auto_now=True)
>     modified  = models.DateTimeField(auto_now_add=True)
>     country   = models.ForeignKey(Country)
> 
> Source of information I am trying to load:
> 
> secs = [
>         [1, None, u'Administrative Offices'], 
>               [2, None, u'Higher Education'], 
>               [3, None, u'Hospitals'], 
>               [4, None, u'Hotels'], 
>               [5, None, u'Schools'], 
>               [6, None, u'Sports']
>          ]
> 
> This is a code snippet from the shell:
> 
>>>> c = Country.objects.get(id=1)
>>>>
>>>> for s in secs:
> ...    newsector = Sector(name=s[2], localname='', country = c)
> ...    newsector.save()
> ... 
> Traceback (most recent call last):
>   File "<stdin>", line 3, in ?
>   File 
> "/usr/lib/python2.4/site-packages/Django-0.95-py2.4.egg/django/db/models/base.py",
>  line 203, in save
>     ','.join(placeholders)), db_values)
>   File 
> "/usr/lib/python2.4/site-packages/Django-0.95-py2.4.egg/django/db/backends/util.py",
>  line 12, in execute
>     return self.cursor.execute(sql, params)
> psycopg.ProgrammingError: ERROR:  syntax error at or near "Offices" at 
> character 105
> 
> INSERT INTO "data_sector" 
> ("name","localname","created","modified","country_id") VALUES (Administrative 
> Offices,'','2006-11-18 21:36:31.145400','2006-11-18 21:36:31.145474',1)
> 
> 
> Psycopg version : python-psycopg 1.1.21-10
> Django version  : 0.95
> OS              : Debian Testing
> 
> 


--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to