Python 中 mySQL 中的语句

class DeleteInventorybusiness(BaseBusiness):
    def DeleteInventory(self,Delete_goodsID):

        DeleteInventory_sql=("DELETE FROM inventoryinformation WHERE goodsID= %s")

        asd = self.conn.execute(DeleteInventory_sql,Delete_goodsID)

        return asd

这就是一个删除的例子,红色的字体才是SQL  语句,这里 用  %s   代替了传入的参数   Delete_goodsID     然后用其父类BaseBusiness 里面的  execute 方法,来执行SQL语句就好了,下面的例子也是一样的

查询就用

select managerID,managerPassword from manager where managerID= %s and managerPassword= %s

接下来是修改

manager_sql=("update manager set managerPassword= %s where managerID= %s ")

添加:

sql=("INSERT INTO customer(customerID,customerName,customerAddress,customerBankAccount,customerPayee,"
             "customerAccountNumber,customerContacts,companyTelephone,contactPhone,customerFax) VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)")

这样,基本的增删改查都有了,而且SQL语句中因为是传入的参数,可以避免一些SQL注入问题,还是比较好的

posted @ 2016-10-15 16:07  黑色白沙  阅读(501)  评论(0编辑  收藏  举报