728x90

CASE 1) 

(24.02.10) 

'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 \'You and what army?"\nI guess they\'re talking about you and me\nBaby, nobody will l\' at line 23'

 

python dedent์—์„œ backspace ์‚ฌ์šฉ ๋‚จ๋ฐœ๋กœ ์ œ๋Œ€๋กœ ๋œ query๊ฐ€ ์ˆ˜ํ–‰๋˜์ง€ ์•Š์•„ ์ƒ๊ธฐ๋Š” ๋ฌธ์ œ,, 

 

Python ํ˜น์€ ๋‹ค๋ฅธ ์–ธ์–ด๋“ค ๋Œ€๋ถ€๋ถ„ ๋“ค์—ฌ ์“ฐ๊ธฐ(indent)์— ๋ฏผ๊ฐํ•ด sqlparse ๋ชจ๋“ˆ๋กœ query์˜ ์ค„๋ฐ”๊ฟˆ upper case๋ฅผ ์ž๋™์œผ๋กœ ์ „์ฒ˜๋ฆฌ ํ•ด์ค„ ์ˆ˜ ์žˆ๋‹ค.

import sqlparse
raw = 'select * from foo; select * from bar;'
print(sqlparse.format(raw, reindent=True, keyword_case='upper'))
SELECT *
FROM foo;

SELECT *
FROM bar;

https://github.com/andialbrecht/sqlparse

 

GitHub - andialbrecht/sqlparse: A non-validating SQL parser module for Python

A non-validating SQL parser module for Python. Contribute to andialbrecht/sqlparse development by creating an account on GitHub.

github.com

 

๋ฐ˜์‘ํ˜•
๋‹คํ–ˆ๋‹ค