Python操作数据库SQLite --------2

#!/usr/bin/env python
# -*- coding: utf-8 -*-

#导入日志及SQLite3模块
import logging
import logging.config
import sqlite3

#日志配置文件名
LOG_FILENAME = 'logging.conf'

#日志语句提示信息
LOG_CONTENT_NAME = 'sqlite_log'

#SQLite数据库名称
DB_SQLITE_PATH = ".\\db\\sqlite_pytest.db"

def log_init(log_config_filename, logname):
    '''
    Function:日志模块初始化函数
    Input:log_config_filename:日志配置文件名
           lognmae:每条日志前的提示语句
    Output: logger
    author: socrates
    date:2012-02-11
    '''
    logging.config.fileConfig(log_config_filename)
    logger = logging.getLogger(logname)
    return logger

def operate_sqlite3_tbl_product():
    '''
    Function:操作SQLITE3数据库函数
    Input:NONE
    Output: NONE
    author: socrates
    date:2012-02-11
    '''  
    sqlite_logger.debug("operate_sqlite3_tbl_product enter...") 
    
    #连接数据库  
    try:
        sqlite_conn = sqlite3.connect(DB_SQLITE_PATH)
    except sqlite3.Error, e:
         print 'conntect sqlite database failed.'
         sqlite_logger.error("conntect sqlite database failed, ret = %s" % e.args[0])    
         return    
     
    sqlite_logger.info("conntect sqlite database(%s) succ." % DB_SQLITE_PATH) 
     
    #获取游标 
    sqlite_cursor = sqlite_conn.cursor()
    
    #删除表
    sql_desc2 = "DROP TABLE IF EXISTS tbl_product3;"
    try:
        sqlite_cursor.execute(sql_desc2)
    except sqlite3.Error, e:
         print 'drop table failed'
         sqlite_logger.error("drop table failed, ret = %s" % e.args[0])
         sqlite_cursor.close()
         sqlite_conn.close()      
         return
   

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值