Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow to shorten long strings in sql logs #80

Closed
RonnyPfannschmidt opened this issue Jul 8, 2013 · 2 comments
Closed

allow to shorten long strings in sql logs #80

RonnyPfannschmidt opened this issue Jul 8, 2013 · 2 comments

Comments

@RonnyPfannschmidt
Copy link
Contributor

when storing text blobs or larger sessions in the database,
the sql display gets pretty ugly due to a single string spanning so many lines

@andialbrecht
Copy link

FWIW, I've just added an option to sqlparse to truncate long string literals (see andialbrecht/sqlparse@204b779).

However, devserver still logs statements, that won't be parsed correctly by sqlparse to use this new option.

Here's for example a statement from the log (added some line breaks for readability):

UPDATE "django_session" SET "session_data" = OWExYWFiM2NjZDI0NTNlNDU3NDc0MTY2MTI3OTk3ODcyOWQ4NzY2ODqAAn1xAShVD2RqYW5nb19sYW5nd
WFnZVUCZGVVEl9hdXRoX3VzZXJfYmFja2VuZFUjZGxnaWNlcnQuYXV0aC5iYWNrZW5kcy5Nb2RlbEJhY2tlbm
RVDV9hdXRoX3VzZXJfaWRLFFUMb3JkZXJfc2VhcmNofXECKFUGc3RhdHVzSwFVBnJvd3NwcEsKdXUu, 
"expire_date" = 2013-07-09 09:45:58.538040
WHERE "django_session"."session_key" = 5du9r23h5sl2kvqdlhumxsm7nu4r0qpo;

Some quotes would be needed to make it valid SQL:

UPDATE "django_session" SET "session_data" = 'OWExYWFiM2NjZDI0NTNlNDU3NDc0MTY2MTI3OTk3ODcyOWQ4NzY2ODqAAn1xAShVD2RqYW5nb19sYW5n
dWFnZVUCZGVVEl9hdXRoX3VzZXJfYmFja2VuZFUjZGxnaWNlcnQuYXV0aC5iYWNrZW5kcy5Nb2RlbEJhY2tlbm
RVDV9hdXRoX3VzZXJfaWRLFFUMb3JkZXJfc2VhcmNofXECKFUGc3RhdHVzSwFVBnJvd3NwcEsKdXUu', 
"expire_date" = '2013-07-09 09:45:58.538040'
WHERE "django_session"."session_key" = '5du9r23h5sl2kvqdlhumxsm7nu4r0qpo';

With the corrected statement sqlparse would produce the following results:

>>> print(sqlparse.format(sql, reindent=True, truncate_strings=40))
UPDATE "django_session"
SET "session_data" = 'OWExYWFiM2NjZDI0NTNlNDU3NDc0MTY2MTI3OTk3[...]',
    "expire_date" = '2013-07-09 09:45:58.538040'
WHERE "django_session"."session_key" = '5du9r23h5sl2kvqdlhumxsm7nu4r0qpo';

Edit: Just noticed that this is related to #66

@RonnyPfannschmidt
Copy link
Contributor Author

closing to get if off my plate on github

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants