如何在postgresql中模拟oracle的dual表,来测试数据库最基本的连接功能?

还好,网上弄到的,,没有dual的数据库,可以试图用select函数不带from数据表的方式来实现返回值。

一段测试代码:

 

try:
        conn = psycopg2.connect(database=db.service_name, user=db.username, password=password, host=db.ip, port=db.port)
        cursor = conn.cursor()
    except Exception, e:
        context_dict = {'msg': e, 'address': db.ip, 'port': db.port}
        return render(request, 'sar/release_info.html', context_dict)
    sql = "SELECT 'OK' AS txt"
    try:
        cursor.execute(sql)
        x = cursor.fetchone()[0]
    except Exception,e:
        context_dict = {'msg': "密码认证通过,但SELECT功能出错", 'address': db.ip, 'port': db.port}
        return render(request, 'sar/release_info.html', context_dict)
    finally:
        cursor.close()
        conn.close()
    if x == 'OK':
        context_dict = {'msg': "数据库连接正常", 'sql': sql, 'address': db.ip, 'port': db.port }
        return render(request, 'sar/release_info.html', context_dict)

如何在postgresql中模拟oracle的dual表,来测试数据库最基本的连接功能?

上一篇:Kali中搭建vulhub时镜像git失败


下一篇:单店营收平均提升达8%-10% 阿里系小程序矩阵的风口来了!