search

Home  >  Q&A  >  body text

sql - 这段代码如何pythonic,数据库查询

PHPzPHPz2893 days ago271

reply all(1)I'll reply

  • 高洛峰

    高洛峰2017-04-18 09:36:51

    • You can try not to spell the SQL statement yourself, but use the functions that come with the system library, such as

    results = cur.select(table = 'articles', columns = ['id','link','is_keywords_avaliable'], where = correct_parms) # 具体的参数我也记得不清楚,可以自己查查看。
    • Use format strings to easily replace parameters.

    sql = "select {columns} from {table} {is_where} {condition}".format(columns = 'id, link, is_keywords_available', table = 'articles', is_where = "where", condition = ".....")

    reply
    0
  • Cancelreply