Well, the quotes thing seems perhaps to be a bit of a red herring... I
have taken ALL the fields out of my model and form (although they
still remain in the database itself, I think Django will ignore their
existence), apart from the foreign key to the User, and the telephone
number. (Yes, this is just a user profile, following the instructions
in the manual!).

I am left with a models.py which contains:
class Userprofile(models.Model):
    user=models.OneToOneField(
        User,
        editable=False,
        unique=True,
        )
    telephone=models.CharField(
        blank=True,
        max_length=20,
        )

How much simpler could it get? :)

The error message is now:
(1064, "You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use
near ') WHERE `app_userprofile`.`id` = 1' at line 1")

Now I have tried typing directly into the mySql command line:

UPDATE `app_userprofile` SET `telephone`=("'123 123'");

This works, as expected, but the superfluous single quotes within the
telephone number also go in the field - this is not a problem though,
because I guess they are filtered out before the mySql engine sees
them, otherwise *everybody* would be complaining! Or if not, it might
be a problem later, but I don't think it's relevant to THIS problem.
Which is, I can't seem to update a profile record, even though it only
contains one field, and at this stage I don't care if it updates
*correctly*, just so long as it updates *something*!

However, it could be that the problem is lurking at the beginning of
the SQL statement, which I haven't been able to see yet....
...so, how does one go about looking at the actual SQL which is passed
to the database engine? Is this possible? I suppose it must be, if I
spent several hours diving into the Django source, but hopefully
somebody knows an easier way? Somebody? Anybody?

On Jun 30, 10:32 pm, Simon Tite <[EMAIL PROTECTED]> wrote:
> Thanks Scott, for the speedy reply.
>
> "gender" is defined in models.py as
>
> gender=models.CharField(max_length=1,default="U",choices=GENDERS)
>
> and GENDERS=(("M","Male"),("F","Female"),("U","Uncertain"))
>
> However, when you say that it's a three-character string including
> single-quotes, where did the single quotes come from? Presumably part
> of Django's attempt to "sanitise" the SQL string, by escaping quotes
> and field names etc? In fact, the value of each field displayed in the
> error message seems to be enclosed in escaped single quotes, eg, ....
>
> 'fieldname' = ("\'fieldvalue\'")
>
> I assume this is part of a SQL UPDATE statement, eg, ....
>
> UPDATE app_userprofile VALUES 'gender' = 'F', 'address' = '97 Rochdale
> Road..', ... WHERE ...
>
> which, if I remember SQL syntax correctly, would be a valid way of
> updating a single record. But certainly it seems that there is an
> extra "coating" of quotes, and what is really being passed to mySql is
> something like...
>
> UPDATE app_userprofile VALUES 'gender' = " ' F ' ", ... (i've put in
> extra spaces between the quotes for clarity).
>
> In which case your suggestion that it is trying to update a single-
> character field with three characters makes a lot of sense. So, ok
> genius :), where are the extra quotes coming from, and how can I get
> rid of them?
>
> --Simon
>
> On Jun 30, 10:02 pm, "Scott Moonen" <[EMAIL PROTECTED]> wrote:
>
> > Simon, my guess is that the error doesn't have to do with the truncation you
> > see, but that something that is passing the error along is trying to be
> > helpful by truncating the string -- one hopes in such a way that the error
> > is still evident. :)
>
> > Looking at the snippet you've posted, I wonder how the 'gender' field is
> > defined.  You are storing the three-character string 'Y' into it (including
> > single quotes).  Do you expect to be able to store three characters into it,
> > or only one character?
>
> >   -- Scott
>
> > On Mon, Jun 30, 2008 at 3:47 PM, Simon Tite <[EMAIL PROTECTED]> wrote:
>
> > > I get the following error when trying to save a model -
> > > "userprofile.save()" -
>
> > > (1064, 'You have an error in your SQL syntax; check the manual that
> > > corresponds to your MySQL server version for the right syntax to use
> > > near \'), `gender` = ("\'F\'",), `hideyear` = (\'0\',), `address` =
> > > ("\'97 Rochdale Rd\\\\r\\\\n\' at line 1')
>
> > > The data comes from a form, one of the fields being "address". It
> > > would appear that the final part < `address` = ("\'97 Rochdale Rd\\\\r\
> > > \\\n\'  > does not have a closing parenthesis.
>
> > > If I put more data into the textbox for the address field, this is the
> > > result:
>
> > > ProgrammingError at /form/profile/
> > > (1064, 'You have an error in your SQL syntax; check the manual that
> > > corresponds to your MySQL server version for the right syntax to use
> > > near \'), `gender` = ("\'F\'",), `hideyear` = (\'0\',), `address` =
> > > ("\'97 Rochdale Manor Ho\' at line 1')
>
> > > This seems like there is a larger SQL command, which has been
> > > truncated at exactly the same character position. This theory is borne
> > > out by other experiments: if the address field is left blank, the next
> > > field "telephone" is truncated at the same position...
>
> > > This is the version of mySql:-
>
> > > $ mysql -V
> > > mysql  Ver 14.12 Distrib 5.0.51a, for debian-linux-gnu (i486) using
> > > readline 5.2
> > > $
>
> > > I'm using Django trunk 7788, from +/- 0100 GMT today 30/6/2008.
>
> > > So, I wonder how I can look at the full text of the string which is
> > > being passed to mySql, and whether anyone knows of any string size
> > > limitation in Django SQL statements (this seems unlikely, as I would
> > > probably have found it in the forum somewhere: there are lots of posts
> > > about error 1064, but none AFAIK seem to reflect my problem), or maybe
> > > there is a mySql setting which allows/disallows incomplete lines?
> > > Maybe Django was going to follow with the rest of the statement, but
> > > mySql threw an error?
>
> > > Hmmm. Think I'll re-read the mySql manual... but in the meantime, does
> > > anyone have any ideas?
>
> > --http://scott.andstuff.org/|http://truthadorned.org/
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to