xml地图|网站地图|网站标签 [设为首页] [加入收藏]
汽车工程学院
分类:操作系统

最近项目中需要用到Python调用oracle实现读写操作,踩过很多坑,历尽艰辛终于实现了。性能怎样先不说,有方法后面再调优嘛。现在把代码和注意点记录一下。

图片 1

usage

在使用 gdb debug 程式前,
compile 需要加 -g 產生 debug information

gcc -g

1. 所需Python工具库

Do not print the introductory and copyright messages.

-quiet
-q "Quiet". Do not print the introductory and copyright messages. These messages are also suppressed in batch mode.

$ gdb a.out

GNU gdb (Ubuntu 7.7.1-0ubuntu5~14.04.2) 7.7.1
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from a.out...done.
(gdb)

$ gdb -q a.out

Reading symbols from a.out...done.
(gdb)

   cx_Oracle,pandas,可以使用通过控制台使用pip进行安装(电脑中已经安装)

get the address of variable

(gdb) p &a

图片 2

difference between (gdb)r with (gdb) start

break-through@breakthrough-ThinkPad-T460p:~/working_space/test/5$ gdb -q a.out
Reading symbols from a.out...done.
(gdb) r
Starting program: /home/break-through/working_space/test/5/a.out 
test.a = 1, test.b=2, test.c=3
[Inferior 1 (process 7607) exited normally]
(gdb) p &test.a
No symbol "test" in current context.

break-through@breakthrough-ThinkPad-T460p:~/working_space/test/5$ gdb -q a.out
Reading symbols from a.out...done.
(gdb) start
Temporary breakpoint 1 at 0x400535: file container_of.c, line 11.
Starting program: /home/break-through/working_space/test/5/a.out 

Temporary breakpoint 1, main () at container_of.c:11
11          test.a = 1;
(gdb) p &test.a
$1 = (int *) 0x7fffffffddb0

 

print source code

(gdb) list

  1. 实现查询操作

Display assemble code

(gdb) disassemble

#工具库导入

Setting breakpoint

(gdb) b line_number

import pandas as pd

Clear breakpoint

(gdb) clear line_number

import cx_Oracle

Deleting all breakpoints

(gdb) delete

# 注:设置环境编码方式,可解决读取数据库乱码问题
import os
os.environ['NLS_LANG'] = 'SIMPLIFIED CHINESE_CHINA.UTF8'

Continue running your program (after stopping, e.g. at a breakpoint).

(gdb) c

#实现查询并返回dataframe

Execute next program line

def query(table)

Step into

(gdb) step

    host = "127.0.0.1"    #数据库ip
    port = "1521"     #端口
    sid = "test"    #数据库名称
    dsn = cx_Oracle.makedsn(host, port, sid)

Step over

(gdb) next

    #scott是数据用户名,tiger是登录密码(默认用户名和密码)
    conn = cx_Oracle.connect("scott", "tiger", dsn)  

Watchpoint

本文由澳门新葡亰手机版发布于操作系统,转载请注明出处:汽车工程学院

上一篇:上帝模式,DOS下命令符开启wifi无internet访问解决 下一篇:计算机的基本构成,记一次无法登录
猜你喜欢
热门排行
精彩图文