简体   繁体   中英

pymysql reading \n characters. how can I stop \n characters being run in an .sql file?

Error:

pymysql.err.ProgrammingError: (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 'CREATE 
PROCEDURE 
`sp_listProducts` (\n    SELECT p.product_id\n             , p.pr' at line 3")

SQL:

CREATE PROCEDURE `sp_listProducts` ()
    SELECT p.product_id
         , p.product
         , u.unit
         , p.unit_quantity
         , p.unit_weight
         , p.pr_number
         , pj.project_code
         , sec.sector
         , p.supplier
         , p.packaging_info
         , loc.location                        AS project_location
         , p.comments
         , loc.location_id
         , p.product_price
         , p.price_currency
         , p.gik_number
         , p.gik_stock_id
         , p.gik_supplier_id                   AS supplier_id
         , gik.gik_supplier
         , IF(tr.in_stock > 0, tr.in_stock, 0) as in_stock
FROM tbl_product AS p
             # get all FK values for display
             LEFT JOIN tbl_unit AS u ON p.unit_id = u.unit_id
             LEFT JOIN tbl_project AS pj ON p.project_id = pj.project_id
             LEFT JOIN tbl_location AS loc ON pj.location_id = loc.location_id
             lEFT JOIN tbl_sector AS sec ON p.sector_id = sec.sector_id
             LEFT JOIN tbl_gik_supplier AS gik ON p.gik_supplier_id = gik.gik_supplier_id
             LEFT JOIN (
    SELECT product_id
             , SUM(IF(trans_type IN ('in', 'count-gain', 'wb-gain'), trans_quantity, 0))                                                as inflow
             , SUM(IF(trans_type IN ('out', 'count-loss', 'wb-loss'), trans_quantity, 0))                                               as outflow
             , SUM(IF(trans_type IN ('in', 'count-gain', 'wb-gain'), trans_quantity, 0)) - SUM(IF(trans_type IN ('out', 'count-loss', 'wb-loss'), trans_quantity, 0)) as in_stock
    FROM tbl_transaction
    WHERE deleted=0
    GROUP By product_id
) tr
                                 ON p.product_id = tr.product_id
ORDER BY p.product_id ASC;

I've tried changing the encoding to UTF-8 to no avail. I've also set the project settins.json "files.encoding": "utf8" in vscode; didn't work. How do I get rid of the "\\n" characters being read?

\\n is not the villain. Based on the error message, it is either the CREATE token or whatever came immediately before it. I expect it to be a syntax error in the DELIMITER statement. A common cause:

DELIMITER//   -- bad; need space after "DELIMITER" and the delimiter

Check the docs on pymysql -- perhaps DELIMITER is not used, and it is something else.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM