6月笔记
?
?
--- 需要考慮最后一個字段 //get fields of one row from a char* str comparted by the compart char long CGMDBTable::GetLineFromStr(char* str, char seg) {char* phead = str;char* ptail = str;int ipos = 0;while (*ptail != '/0'){if (*ptail == seg){if (ptail != phead){*ptail = '/0';if ((pFields[ipos])->type == DB_SQL_T_DOUBLE){*(pFields[ipos]) = atof(phead);}else{*(pFields[ipos]) = phead;}}phead = ptail + 1;ipos++;}ptail++;}if (ptail != phead){*ptail = '/0';if ((pFields[ipos])->type == DB_SQL_T_DOUBLE){*(pFields[ipos]) = atof(phead);}else{*(pFields[ipos]) = phead;}}Insert();return 1; }-- 注意long 和 double類型不能夠使用內存拷貝的方式賦值,因為存儲方式不一樣-- 體會封裝的極大好處,如oci函數的封裝-- 2011-3-15 sqlldr 生成的日志中,有sqlldr的一些詳細參數,如入庫方式truncate還是append--1.查看鎖表進程 select s.SID, s.SERIAL#,lo.ORACLE_USERNAME,lo.OS_USER_NAME,do.object_name, lo.LOCKED_MODEfrom v$locked_object lo, dba_objects do, v$session s where lo.OBJECT_ID = do.object_id and lo.SESSION_ID = s.SID; --殺掉鎖表進程2 --根據剛才查出的鎖表進程的SID和SERIAL#的值,執行alter system kill session 'SID,SERIAL#'解除鎖定 如:alter system kill session '738,1429'查看Oracle錯誤號含義 oerr ora 942 00942, 00000, "table or view does not exist" // *Cause: // *Action:date -d yesterday '+%Y%m%d' 20110320 > date -d tomorrow '+%Y%m%d' 20110322用來判斷月末非常有用date -d tomorrow '+%d' 如果是01 則當天是月末最后一天--注意group by的用法select id, count(id) tt from student t group by id having count(id) > 1;sqlplus可以采用這種方式進行連接>sqlplus niop_dw/niop_dw@10.41.20.113:1521/orcl2011-4-26在使用gmdb進行批量數據插入的時候,如果批量條數太大,如10000,會出錯--cat .profileexport ORACLE_BASE=$HOME export ORACLE_HOME=$ORACLE_BASE/product/11.1.0/db_1 export ORACLE_SID=orcl export NLS_LANG=american_america.ZHS16GBK export NLS_DATE_FORMAT="YYYY-MM-DD HH:mi:ss" export ORA_NLS33=$ORACLE_HOME/nls/data export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH export PATH=$PATH:$ORACLE_HOME/bin-- COCISession ociSess; ociSess.Connect(pValue); COCIStmt conn(&ociSess); OciTable tb;tb.SetConnection(&conn);2011-5-6class A { public: // A() // { // }A(int i){a = i;} protected: private:int a; };class B:public A{B(){}B(int i, int j):A(i){b = j;}int b; }; int main() {}這樣會出錯, 基類的默認構造函數被覆蓋了--bi0001:~ # mkdir /etc/TimesTen bi0001:~ # touch /etc/TimesTen/instance_info bi0001:~ # groupadd timesten bi0001:~ # groupadd ttadmin bi0001:~ # bi0001:~ # useradd -g ttadmin -m -d /ttadm -s /bin/ksh ttadm bi0001:~ # bi0001:~ # passwd ttadm Changing password for ttadm. New Password: Bad password: too simple Reenter New Password: Password changed. bi0001:~ # bi0001:~ # bi0001:~ # chgrp -R ttadmin /etc/TimesTen bi0001:~ # chmod 775 /etc/TimesTen bi0001:~ # chmod 664 /etc/TimesTen/* bi0001:~ # bi0001:~ # chown -R ttadm:timesten /ttadmTNS_ADMIN will be set to /oracle/app/oracle/product/11.1.0/db_1/network/admin You can change TNS_ADMIN later by running <install_dir>/bin/ttmodinstall../ttisql "DSN=TT_1121"Command> create user test identified by test;User created.Command> grant create session, create any table to test; ./ttisql "DSN=TT_1121;uid=test;pwd=test"ttDaemonAdmin –restart --- 查詢時間點數據,在delete刪除數據后進行數據恢復時很有用 select * from student as of timestamp to_timestamp('2011-05-20 16:46:40', 'yyyy-mm-dd hh24:mi:ss');迷糊了,竟然寫出了這樣的語句 insert into test(2, 'HanMm')報錯后還以為是內存庫的問題,竟然還去重啟,很久才看出來insert into test values(2, 'HanMm')編譯TT ODBC g++ -I/ttadm/TimesTen/tt1121/include -L/ttadm/TimesTen/tt1121/lib -ltten -lgcc_s noname1.cpp客戶端 g++ -I/ttadm/TimesTen/tt1121/include -L/ttadm/TimesTen/tt1121/lib -lttclient -lgcc_s ins.cpp ttadm@bi0001:/ttadm/TimesTen/tt1121/test> ./a.out [TimesTen][TimesTen 11.2.1.8.0 CLIENT]Cannot find the requested DSN (tt_1121) in ODBCINI /ttadm/TimesTen/tt1121/info/sys.odbc.ini設置環境 ttadm@bi0001:/ttadm/TimesTen/tt1121/quickstart> . ./ttquickstartenv.sh NOTE: TNS_ADMIN is already set in environment - /ttadm/TimesTen/tt1121/network/admin/samplesLD_LIBRARY_PATH set to /ttadm/TimesTen/tt1121/lib:/ttadm/TimesTen/tt1121/ttoracle_home/instantclient_11_1:/oracle/app/oracle/product/11.1.0/db_1/libANT_HOME set to /ttadm/TimesTen/tt1121/3rdparty/antPATH set to /ttadm/TimesTen/tt1121/bin:/ttadm/TimesTen/tt1121/quickstart/sample_code/oci:/ttadm/TimesTen/tt1121/quickstart/sample_code/odbc:/ttadm/TimesTen/tt1121/quickstart/sample_code/odbc/xla:/ttadm/TimesTen/tt1121/quickstart/sample_code/jdbc:/ttadm/TimesTen/tt1121/quickstart/sample_code/odbc_drivermgr:/ttadm/TimesTen/tt1121/quickstart/sample_code/proc:/ttadm/TimesTen/tt1121/quickstart/sample_code/ttclasses:/ttadm/TimesTen/tt1121/quickstart/sample_code/ttclasses/xla:/ttadm/TimesTen/tt1121/ttoracle_home/instantclient_11_1:/ttadm/TimesTen/tt1121/ttoracle_home/instantclient_11_1/sdk:/ttadm/TimesTen/tt1121/3rdparty/ant/bin:/ttadm/bin:/usr/local/bin:/usr/bin:/usr/X11R6/bin:/bin:/usr/games:/opt/gnome/bin:/opt/kde3/bin:/usr/lib/mit/bin:/usr/lib/mit/sbin:/oracle/app/oracle/product/11.1.0/db_1/binCLASSPATH set to /ttadm/TimesTen/tt1121/lib/ttjdbc5.jar:/ttadm/TimesTen/tt1121/lib/orai18n.jar:/ttadm/TimesTen/tt1121/lib/timestenjmsxla.jar:/ttadm/TimesTen/tt1121/3rdparty/jms1.1/lib/jms.jar:/ttadm/TimesTen/tt1121/quickstart:/ttadm/TimesTen/tt1121/quickstart/sample_code/jdbc:.NOTE: The demos use system DSNs defined in/ttadm/TimesTen/tt1121/info/sys.odbc.iniTo use your own DSNs, they must be defined in ~/.odbc.ini, oryou may set the environment variable ODBCINI to point tothe correct file.之前沒有調通的原因可能是LD_LIBRARY_PATH 中沒有配置新的庫版本通過修改LD_LIBRARY_PATH進行驗證發現就是這個問題11.1.0.6.0 版本較低通過TNS_ADMIN這個環境變量來找tnsnames.ora 這個文件,根據給定的tnsname來找到SERVICE_NAME,再到sys.odbc.ini 中找起對應的內存庫配置 test0=(DESCRIPTION=(CONNECT_DATA = (SERVICE_NAME = client0)(SERVER = timesten_direct)))客戶端 testct=(DESCRIPTION=(CONNECT_DATA = (SERVICE_NAME = client0)(SERVER = timesten_client)))使用TT提供的庫可以向Oracle中插入數據 ttadm@bi0001:/ttadm/TimesTen/tt1121/network/admin/samples> export TNS_ADMIN=/ttadm/TimesTen/tt1121/network/admin/samples ttadm@bi0001:/ttadm/TimesTen/tt1121/network/admin/samples> ttadm@bi0001:/ttadm/TimesTen/tt1121/network/admin/samples> ttadm@bi0001:/ttadm/TimesTen/tt1121/network/admin/samples> CD /ttadm/TimesTen/tt1121/quickstart/sample_code/oci -ksh: CD: not found [No such file or directory] ttadm@bi0001:/ttadm/TimesTen/tt1121/network/admin/samples> cd /ttadm/TimesTen/tt1121/quickstart/sample_code/oci ttadm@bi0001:/ttadm/TimesTen/tt1121/quickstart/sample_code/oci> ls addemp.c Makefile mo plsqlOCI.c psswds.c README_oci.html README_oci.txt tptbmOCI.c ttadm@bi0001:/ttadm/TimesTen/tt1121/quickstart/sample_code/oci> ttadm@bi0001:/ttadm/TimesTen/tt1121/quickstart/sample_code/oci> ttadm@bi0001:/ttadm/TimesTen/tt1121/quickstart/sample_code/oci> ./mo Dandan count = 1 overdate -d ’3 days ago’ date -d tomorrow date -d ’3 days’---# The Timesten Client entries follow the pattern of: # <NAME> =(DESCRIPTION=(CONNECT_DATA = (SERVICE_NAME = <NAME> )(SERVER = timesten_client))) test0=(DESCRIPTION=(CONNECT_DATA = (SERVICE_NAME = client0)(SERVER = timesten_direct)))testct=(DESCRIPTION=(CONNECT_DATA = (SERVICE_NAME = client0)(SERVER = timesten_client)))-- [client0] TTC_SERVER=tthost0 TTC_SERVER_DSN=TT_1121-- ./mo test/test@testctg++ -o /ttadm/TimesTen/tt1121/test/bin/mo -lpthread -L/ttadm/TimesTen/tt1121/ttoracle_home/instantclient_11_1 -lclntsh main.o database.o OraDB.o SqlUtils.o CSysLog.o SimpleLog.o Field.o OciTable.o--OCIStmtPrepare 在調用錯誤的sql下,沒有返回錯誤./mo test/test@tt_1121在oci程序中,1個連接中的公用commit操作多個線程同時向同一個表里插入數據會出錯測試發現:在同一個連接中,如果有2個線程同時進行插入數據操作(調用OCIStmtExecute),會出錯 DBCON_QUERY_ERROR failed! OCIServerAttach error[ORA-01013: user requested cancel of current operation ]! DBCON_QUERY_ERROR failed! OCIServerAttach error[ORA-24909: call in progress. Current operation cancelled ]! DBCON_QUERY_ERROR failed! OCIServerAttach error[ORA-03114: not connected to ORACLE ]! DBCON_QUERY_ERROR failed! OCIServerAttach error[ORA-03114: not connected to ORACLE ]! 4 DBCON_QUERY_ERROR failed! OCIServerAttach error[ORA-03114: not connected to ORACLE ]! Segmentation fault其效果相當于在一個界面中,先執行一個sql句子,同時再執行另一個sql,就會出錯ttdaemonadmin -restart--- 1個連接中insert沒有commit時,在另一個連接中對同一個表進行truncate時,會出錯 ORA-00054 資源正忙--- 2011-6-14for (int i = 0; i < number; i++){pthread_t id; cout << "i = " << i << endl;pthread_create(&id, NULL, fun, &i); //sleep(3);}在多線程使用的時候出現問題:number 的值為2 , 在函數fun中調用i的時候,其值變成了2不是想要的0 1原因是傳入的是i的地址,多個線程共享這個變量,循環很快的改變了i的值這種情況下,需要在fun中立即使用一個變量保存i的值,來保證程序安全-- top 命令 在顯示后,輸入M ,使顯示按照內存占用排序應用程序中訪問TimesTen比較占用內存PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 24991 ttadm 16 0 447m 31m 20m S 0 0.4 0:00.02 mo 執行的時候程序占用的內存會逐漸增加,后來就趨于穩定-- 2011-6-16使用oci連接oracle時,可以使用EZCONNECT 格式為 192.168.111.102:1521/orcl:server ./mo test/test1@192.168.111.102:1521/orcl:server 或者 ./mo test/test1@192.168.111.102:1521/orclIn TimesTen, sample copies of tnsnames.ora and sqlnet.ora are in the install_dir/network/admin/samples directory. Here is the sqlnet.ora file that TimesTen provides, which supports both tnsnames and easy connect ("EZCONNECT"): # To use ezconnect syntax or tnsnames, the following entries must be # included in the sqlnet.ora configuration. # NAMES.DIRECTORY_PATH= (TNSNAMES, EZCONNECT) With this file, TimesTen will first look for tnsnames syntax in your OCI logon calls. If it cannot find tnsnames syntax, it will look for easy connect syntax.-- ORACLE_SID 數據庫實例名LD_LIBRARY_PATH 對編譯也有影響LD_LIBRARY_PATH=/ttadm/TimesTen/tt1121/lib:/ttadm/TimesTen/tt1121/lib:/ttadm/TimesTen/tt1121/ttoracle_home/instantclient_11_1:/oracle/app/oracle/product/11.1.0/db_1/libORA-44818: Unable to load NLS initialization data from /ttadm/TimesTen/tt1121/nls/dataORA-44818: Error opening ODBCINI file /ttadm/TimesTen/tt1121/info/sys.odbc.ini: Permission deniedORA-57000: TT0622: User oracle does not have group permission to connect to data store -- file "db.c", lineno 9722, procedure "sbDbConnect"-- TimesTen 在安裝的時候設置的有訪問權限限制,如果采用的默認設置,group 其他用戶訪問TimesTen時,需要給用戶設置組(使用root用戶來設置),注意,不要忘記了加上該用戶以前所在的組 usermod -G oinstall,ttadmin oracle usermod: `oinstall' is primary group name.-- groups 查看用戶所在的組,一個用戶可以在多個組中
?
?
?
?
?
總結
- 上一篇: 目标美日德--2018汽车零部件产业国产
- 下一篇: “票链”近期通过区值研究院价值检测