Python SQL query string formatting

后端 未结 10 1513
没有蜡笔的小新
没有蜡笔的小新 2020-12-04 08:51

I\'m trying to find the best way to format an sql query string. When I\'m debugging my application I\'d like to log to file all the sql query strings, and it is important t

10条回答
  •  情歌与酒
    2020-12-04 09:36

    To avoid formatting entirely, I think a great solution is to use procedures.

    Calling a procedure gives you the result of whatever query you want to put in this procedure. You can actually process multiple queries within a procedure. The call will just return the last query that was called.

    MYSQL

    DROP PROCEDURE IF EXISTS example;
     DELIMITER //
     CREATE PROCEDURE example()
       BEGIN
       SELECT 2+222+2222+222+222+2222+2222 AS this_is_a_really_long_string_test;
       END //
     DELIMITER;
    
    #calling the procedure gives you the result of whatever query you want to put in this procedure. You can actually process multiple queries within a procedure. The call just returns the last query result
     call example;
    

    Python

    sql =('call example;')
    

提交回复
热议问题