------ 调试程序 insert into STUDENT nologging ( STUDENT,NAME ) values ( :ID,NAME ) 程序出错 Program received signal SIGSEGV, Segmentation fault. 0x00002ae37133f56d in upirtrc () from /oracle/app/oracle/product/11.1.0/db_1/lib/libclntsh.so.11.1 --------- 11-4 在 void* fun(void* i) { cout << "i = " << i <<" " << *(int*)i << endl; char* p = new char[10]; p[0] = 'h'; p[1] = 'k'; p[2] = '/0'; cout << "&p = " << &p << endl; // *((long int*)i) = (long int)(*(&p)); *((long int*)i) = (long int)p; sleep(10); return (void *)p; } 中最开始 *(int*)i = p; 报错 tt.cpp: In function ‘void* fun(void*)’: tt.cpp:14: error: cast from ‘char*’ to ‘int’ loses precision 在vc6中可以编译通过 按照其错误提示发现,是精度的问题,于是猜想到是int 指针地址程度的问题 在这个linux机器上,机器是64位的,地址应该是long int 类型 可以通过获取地址的方法进行灵活的操作 ----------- #include <iostream.h> #include <pthread.h> #include <unistd.h> void* fun(void* i) { cout << "i = " << i <<" " << *(int*)i << endl; char* p = new char[10]; p[0] = 'h'; p[1] = 'k'; p[2] = '/0'; cout << "&p = " << &p << endl; // *((long int*)i) = (long int)(*(&p)); // *((long int*)i) = (long int)p; *(int *)i = 99; cout << "&i = " << (int*)i << endl; sleep(10); cout << "&i = " << (int*)i << endl; cout << "thread i = " << *(int*) i << endl; return (void *)p; } int main() { char* p = NULL; for(int i = 0; i < 5; i++) { int m = 5 + i; cout << "start m = " << m << " &m = " << &m << endl; pthread_t id; sleep(1); pthread_create(&id, NULL, fun, &m); sleep(1); cout << "m = " << m << endl; m = 11; // p = (char*)m; // cout << p << endl; } sleep(30); cout << "main pro is over : " << endl; return 0; } 在使用多线程时应该注意,传给线程的指针如果是个临时变量的地址,如pthread_create(&id, NULL, fun, &m);中的m 会出现问题,线程中使用的变量在外部被修改或回收 ----- makefile 编译问题 .o 文件名字写错了,应该和cpp文件名一致 ub4 和 size_t 类型不一致,修改替换 ---- 在makefile中有些地方注意不要有空格,由于空格不可见,应该注意 --- 以前的一个Oci程序有问题,select出来的字符串有乱码,当时没有仔细查看 ----- oci的函数太猥琐了 // ub2 tt; if (external_type == SQLT_FLT) { status = OCIDefineByPos(pConn->mystmthp, &dfnhp[ i ], pConn->myerrhp, i+1, (dvoid*)fieldValue[ i ], (sb4)sizeof(double), external_type, 0, 0, 0, OCI_DEFAULT); } else { status = OCIDefineByPos(pConn->mystmthp, &dfnhp[ i ], pConn->myerrhp, i+1, (dvoid*)fieldValue[ i ], (sb4)col_len[ i ], external_type, 0, &tt, 0, OCI_DEFAULT); } 之前打印字符串后,在字符串后面有乱码 OCIDefineByPos 最后倒数第3个参数应该用个指针变量来接收程度 -------- 11-5 vc 中没有long long , 有__int64 编译 /root/test/tora/src/OraDB.h:128: error: ‘__int64’ does not name a type /root/test/tora/src/OraDB.h:133: error: ‘__int64’ does not name a type make: *** [database.o] Error 1 --- 测试select操作时,数字型,字符型 的获取 sqlldr test/test control=/root/test/sql/load.ctl sqlldr test/test control=/root/test/sql/load.ctl data=/root/test/sql/in.txt sqlldr test/test@102_db control=load.ctl data=in.txt ------- 11-8 在windows机器上,如果oracle监听tns没有打开,可以找到bin下的那个监听程序,手工执行 继承类调用基类的构造方法,使用D(int c):C(c) 定义的方法 class C { public: C() { } C(int i) { ii = i; } void oo() { cout << ii << endl; } protected: private: int ii; }; class D:public C { public: D():C(2) { } D(int c):C(c) { } protected: private: }; ---