08-8月、9月

 
  1. #include <assert.h>
  2. void main()
  3. {
  4.     char* p = NULL;
  5.     assert(p != NULL);
  6.     Test a;
  7. }
  8. 执行时会提示错误
  9. 如果这样
  10. #include <iostream.h>
  11. #include "Test.h"
  12. #include <assert.h>
  13. void main()
  14. {
  15.     char* p;
  16.     assert(p != NULL);
  17.     Test a;
  18. }
  19. 程序会照样执行,原因在于没有对p进行初始化,p的值不一定为NULL,这一点不能忘记;
  20. 类的封装调用时,以util中的类的调用为例,先要在Tools 中的options中的directories中进行设置,把各个文件加入;在test中进行调试;
  21. 8-20
  22. //在D盘中生成一个txt文件
  23.     CFileWriter c_write("D://");
  24.     c_write.SetFileName("D://", ".txt", "filename");
  25.     c_write.Open();
  26.     c_write.Append("hello, this is a new file");
  27.     c_write.Close();
  28. /
  29. 为了防止头文件被重复引用,应当用ifndef/define/endif结构产生预处理块。
  30. ///
  31. strlen()
  32. 求出的是字符串的实际长度,不包括'/0'
  33. aTime::aTime(char* date_time):CTime(date_time)
  34. {
  35. }
  36. 调用基类的构造函数
  37. /
  38. 五分钟内,找出下面程序中的三处错误, (非定义和语法错误) 
  39. unsigned char * Test(void
  40.     unsigned char i=0; 
  41.     int j=1000; 
  42.     char* p=NULL; 
  43.     for(i=0;i <j;i++) 
  44.     { 
  45.         strncpy(p,"hello",5); 
  46.     } 
  47.     return &i; 
  48. 注意:不是定义和语法上的错误
  49. 1. p没有分配空间 
  50. 2. i永远小于j,循环不会结束 
  51. 3. 返回局部变量地址
  52. unsigned char * Test(void
  53.     unsigned char i=0; 
  54.     int j=1000; 
  55.     char* p=NULL; 
  56.     for(i=0;i <j;i++) //char类型的i和int类的j做比较;实际编译器不报错!
  57.     { 
  58.         strncpy(p,"hello",5);  //copy字符串溢出
  59.     } 
  60.     return &i;  //返回了局部的变量地址
  61. //
  62. char* test(char* p)
  63. {
  64.     p++;
  65.     return p;
  66. }
  67. void main()
  68. {
  69.     char* p = "njau";
  70.     cout << test(p) << endl;
  71.     cout << p << endl;
  72. }
  73. 结果是
  74. jau
  75. njau
  76. test(p) 返回的是当前的指针,
  77. 在执行函数之后,p的值并没有改变,指向不变;
  78. 这种方式更容易理解
  79. int add(int t)
  80. {
  81.     ++t;
  82.     return t;
  83. }
  84.     int a = 2;
  85.     cout << add(a) << endl;
  86.     cout << a << endl;
  87. 结果是
  88. 3
  89. 2
  90. /
  91. char* strcpy(char* strDest,const char* strSource) 
  92. {
  93.     assert((strDest!=NULL) &&(strSource!=NULL)); 
  94.     while((*strDest++=*strSource++)!='/0'); 
  95.     return strDest; 
  96. char* r_strcpy(char* strDest,const char* strSource) 
  97.     assert((strDest!=NULL) &&(strSource!=NULL)); 
  98.     char* newAdress=strDest; 
  99.     while((*strDest++=*strSource++)!='/0'); 
  100.     return newAdress; 
  101. 第一个函数在执行语句
  102.     char s1[10], s2[10] = "second", *s3 = "hello";
  103.     strcpy(strcpy(s1,s2),s3);
  104. 时,就会出问题
  105. 可以这样理解,第一种方式返回的不是原变量,相当于没有返回值;
  106. /
  107. 2008-8-21
  108. 函数floor()的功能是取整数值,floor(2.7) = 2, floor(2.1) = 2 
  109. 用floorv()来实现四舍五入
  110. int round(double x)
  111. {
  112.     return floor(x + 0.5);
  113. }
  114. 一个类可以访问本类的任何对象的私有成员
  115. 下午
  116. 程序问题
  117.     char c[16];
  118.     char b[3] = "a";
  119.     if (strcpy(c, b) != "a")
  120.     {
  121.         cout << "what's out!/n";
  122.     }
  123. 结果输出了what's out!
  124. 原因在于 不能用 != 进行字符串的比较
  125. 注意"" 和'/0'的区别
  126. 一个是字符串的空,一个是字符结束标识
  127. //
  128. -> 的理解
  129. ->    综合了* 和 . 的功能
  130. p->data 等价于 (*p).data
  131. /
  132. 8-22
  133. typedef 不会产生新的类型,只是仅仅是产生已有的类型的别名
  134. /
  135. LogFile 对当前的exe文件设置日志记录log
  136. ///
  137. 8-23 下午
  138.  在一个Source.bat二进制文件中,有许多自然数,要求找出1000~2000之间的自然数,把他们进行排序,Source.bat有1GB大,要求把排序后的数存到Beat.bat中,要考虑到内存和效率问题。 
  139. 一种方法:不用去排序,统计每个数字出现的次数就可以,即以数字的大小为对象去处理,
  140. 如a[0],表示1000出现的个数,a[1]表示1001出现的个数
  141. 有哈希方法的影子在其中
  142. //
  143. 8-25
  144. 对于赋值函数,应当用“引用传递”的方式返回String对象。如果用“值传递”的方式,虽然功能仍然正确,但由于return语句要把 *this拷贝到保存返回值的外部存储单元之中,增加了不必要的开销,降低了赋值函数的效率。例如:
  145.     String a,b,c;
  146.     …
  147.     a = b;      // 如果用“值传递”,将产生一次 *this 拷贝
  148.     a = b = c;  // 如果用“值传递”,将产生两次 *this 拷贝
  149.     String的相加函数operate + 的实现如下:
  150. String  operate+(const String &s1, const String &s2)  
  151. {
  152.     String temp;
  153.     delete temp.data;   // temp.data是仅含‘/0’的字符串
  154.         temp.data = new char[strlen(s1.data) + strlen(s2.data) +1];
  155.         strcpy(temp.data, s1.data);
  156.         strcat(temp.data, s2.data);
  157.         return temp;
  158.     }
  159. 对于相加函数,应当用“值传递”的方式返回String对象。如果改用“引用传递”,那么函数返回值是一个指向局部对象temp的“引用”。由于temp在函数结束时被自动销毁,将导致返回的“引用”无效。例如:
  160.     c = a + b; 
  161. 此时 a + b 并不返回期望值,c什么也得不到,流下了隐患。
  162. ///
  163. 8-26  晚上
  164. 连接数据库时,其他的文件中要是发生了变化,要再编译,选中文件所在的大类文件,右键,build
  165.     long j = Login("oracle");
  166.     T_ACCT_BALANCE t_table;
  167.     t_table.SetConn(DefaultConnect);
  168.     t_table.SetBatSize(1);
  169.     t_table.SetTableName("ACCT_BALANCE_A");
  170. //
  171. 8-27
  172. PL/SQL
  173. File -> new -> SQLWindow  打开查询界面
  174. ///
  175.     j =t_table.Query();
  176. //  t_table.Query("select balance from ACCT_BALANCE_A");
  177.     int i = 0;
  178.     do {
  179.         cout << t_table.BALANCE.Float() << endl;
  180.         i++;
  181.     } while(t_table.Next() > 0 && i < 10);
  182.     
  183.     
  184.     Logout();
  185.     STRU_CONNECT_STRING stru;
  186.     strcpy(stru.szConstr, "@HADEV");
  187.     strcpy(stru.szPassword, "ams1");
  188.     strcpy(stru.szUserName, "ams1");
  189.     
  190.     Connection con;
  191.     con.Login(stru);
  192.     con.ExecSql(" insert into person  values('Bush');");
  193.     con.Logout();
  194. 问题在哪里?留下这个疑问,怎么访问数据库
  195. ///
  196. 类的私有成员 在标记上有一把锁,要能够一眼看书来
  197. /
  198.   long j = 0;
  199.   char str[1024];
  200.   j = Login("oracle");
  201.   
  202.   CRecords c_Records(DefaultConnect, 1024);
  203.   strcpy(str, "select balance from ACCT_BALANCE_A where balance < 2");
  204.   j = c_Records.Query(str);
  205. //  j = DefaultConnect.ExecSql(str);
  206.   while (j > 0 )
  207.   {
  208.       cout << c_Records.Field(0).Float() << endl;
  209.       j = c_Records.Next();
  210.   }
  211.   Logout();
  212. //
  213.   strcpy(str, "select balance, eff_date from ACCT_BALANCE_A where balance < 2");
  214.   j = c_Records.Query(str);
  215.   while (j > 0 )
  216.   {
  217.       cout << c_Records.Field(0).Float() << "   ";
  218.       cout << c_Records.Field(1).Char() << endl;
  219.       j = c_Records.Next();
  220.   }
  221.   Logout();
  222. /
  223. select * from ACCT_BALANCE_A where balance < 2
  224. select * from person
  225. create table person(name char(20), age int);
  226. drop table person
  227. insert into person values('Mary',17)
  228. //
  229. 8-28
  230. 在插入insert操作时,由于元组有主键,再次插入同样的数据后,就会出问题,主键冲突;
  231. 再次插入时,主键应该不同;
  232. delete是根据主码进行识别删除的,基本的update也是根据主码去识别元组的;
  233.     Connection cc;
  234.     int j = cc.Login ("oracle") ;
  235.     if (j > 0)
  236.     {
  237.         cout << "登录/n";
  238.     }
  239.     CRecords c_Records(cc, 1024);
  240.     j = c_Records.Query("select * from person");
  241.     cout << c_Records.Field(0).Char() << endl;
  242.     cc.Logout();
  243. //
  244. 赋值函数不可忽略
  245. 如果不主动编写拷贝构造函数和赋值函数,编译器将以“位拷贝”的方式自动生成缺省的函数。倘若类中含有指针变量,那么这两个缺省的函数就隐含了错误。以类String的两个对象a,b为例,假设a.m_data的内容为“hello”,b.m_data的内容为“world”。
  246. 现将a赋给b,缺省赋值函数的“位拷贝”意味着执行b.m_data = a.m_data。这将造成三个错误:一是b.m_data原有的内存没被释放,造成内存泄露;二是b.m_data和a.m_data指向同一块内存,a或b任何一方变动都会影响另一方;三是在对象被析构时,m_data被释放了两次。
  247. ///
  248. 2008-8-29
  249. 关于表类的Query的参数问题
  250.     j = t_table.Query(" balance < 2");
  251. 找到问题所在了,这里的参数表示查找的条件,但是不用加where这个词
  252. /
  253. Oracle数据库的使用
  254. 选择 运行SQL命令行
  255. SQL> conn/as sysdba
  256. 接下来就可以进行操作了
  257. 注意,语句结束要加上分号;
  258. SQL>
  259. SQL> create table person(name char(20), age int);
  260. 表已创建。
  261. SQL> insert into person values('Mary', 17);
  262. 已创建 1 行。
  263. SQL> select * from person;
  264. NAME                                            AGE
  265. ---------------------------------------- ----------
  266. Mary                                             17
  267. SQL> save all
  268. 已创建 file all.sql
  269. SQL> shutdown abort
  270. ORACLE 例程已经关闭。
  271. /
  272. 2008-9-1
  273. D:/time>
  274. D:/time>cd D:/time/Mo/Debug
  275. D:/time/Mo/Debug>d
  276. /cygdrive/d/time/Mo/Debug/:
  277. rwx------  sun:None  168K  Aug 04 02:40  Mo.exe
  278. rwx------  sun:None  190K  Aug 04 02:40  Mo.ilk
  279. rwx------  sun:None  199K  Aug 04 02:01  Mo.pch
  280. rwx------  sun:None  409K  Aug 04 02:40  Mo.pdb
  281. rwx------  sun:None  168K  Aug 04 02:40  myadd.exe
  282. rwx------  sun:None   33K  Aug 04 02:46  vc60.idb
  283. rwx------  sun:None   44K  Aug 04 02:46  vc60.pdb
  284. 7 regular files in directory, with a total size of 1.2M.
  285. D:/time/Mo/Debug>d              输入d,读取内容
  286. cd  进入路径
  287. cd.. 退回上一层目录
  288. ///
  289. 2008-9-2
  290. If an unsized array is the last element of a structure, the sizeof operator returns the size of the structure without the array. 
  291. ========================================== 
  292. struct
  293.     int i; 
  294.     int a[]; 
  295. }a; 
  296. sizeof(a);不包含最后数组的大小
  297. struct A{
  298.         int id;
  299.         char name[];
  300.     };
  301.     char *name = "csdn";
  302.     A *a = (A *)malloc(sizeof(A) + sizeof(name));
  303.     a->id = 23;
  304.     strcpy(a->name, name);
  305. ///
  306. itoa()
  307. itoa        itoa
  308. 功 能: 把一整数转换为字符串
  309. 用 法: char *itoa(int value, char *string, int radix);
  310. 详细解释:itoa是英文integer to string a(将整形数转化为一个字符串,并将值保存在a中)
  311. 的缩写.其中value为要转化的整数, radix是基数的意思,即先将value转化为几进制的数,之后在保存在a 中.
  312. 作用:实现数制之间的转化
  313. 比较:ltoa,其中l是long integer(长整形数)
  314. 备注:该函数的头文件是"stdlib.h" 
  315. atoi()
  316. //
  317. 9-3
  318. /*
  319. int main(int argc, char** argv)
  320. {
  321.     int a = atoi("2.1.");
  322.     cout << a;
  323. //  int b = atoi(argv[1] );
  324. //  int c = atoi(argv[2] );
  325. //  cout << b + c << endl;
  326.     return 0;
  327. }
  328. */
  329. /
  330. 9-4
  331. 读文件
  332. #include <iostream.h>  
  333. #include <fstream.h>
  334. #include <stdlib.h>
  335. void main()
  336. {
  337. //  char a[1000];int i = 0;
  338.     char filename1[256], filename2[256];
  339.     cout<<"输入源文件名:";    /  如   D:/from.txt
  340.     cin>>filename1;
  341.     cout<<"输入目的文件名";
  342.     cin>>filename2;
  343.     ifstream infile(filename1);
  344.     ofstream outfile(filename2);
  345.     if (!infile)
  346.     {
  347.         cout<<"不能打开输入文件:"<<filename1<<'/n';
  348.         exit(1);
  349.     }
  350.     if (!outfile)
  351.     {
  352.         cout<<"不能打开目的文件: "<<filename2<<'/n';
  353.         exit(2);
  354.     }
  355.     char ch;
  356.     while (infile.get(ch))
  357.     {
  358. //      a[i++] = ch;
  359. //      ch = ch^*'1';
  360. //      ch = ch - 1;
  361.         outfile.put(ch);
  362.     }
  363. //  a[i] = '/0';
  364.     infile.close();
  365.     outfile.close();
  366. //  cout<<a;
  367.     
  368. }
  369. */
  370. ///
  371. 9-5
  372. sprintf中有分行时,不能加上逗号,
  373.     sprintf(buf, "%s",
  374.         "abc"
  375.         "/nvv"
  376.         "aaa");
  377. //
  378. 9-6
  379. 指针应该指向实在的空间
  380. int* p = new int a;
  381. 结构体的指针也一样
  382. 应用中,指针要指向实际存在的结点
  383. /
  384. 9-7
  385. class A
  386. {
  387. public:
  388.     int value;
  389.     A()
  390.     {
  391.         value = 0;
  392.     }
  393. protected:
  394. private:
  395. };
  396. void add(A a)
  397. {
  398.     a.value++;
  399. }
  400. void main()
  401. {
  402.     A a;
  403.     cout << a.value << endl;
  404.     add(a);
  405.     cout << a.value << endl;
  406. }
  407. 结果是
  408. 0
  409. 0
  410. 函数参数的问题,对于类同样如此
  411. //
  412. void insert(char *dtr, char *str, int locat) 
  413. {                    
  414.     dtr+=locat;
  415.     locat=0;
  416.     while(*str)
  417.     {
  418.         while(*str)
  419.         {
  420.             *dtr^=*str;
  421.             *str^=*dtr;
  422.             *dtr^=*str;//这里进行交换
  423.             str++;
  424.             dtr++;
  425.             locat++;
  426.         }
  427.         str-=locat;
  428.         locat=0;
  429.     }
  430. }
  431. int main()
  432. {
  433.     char str1[100]="1234567890";    //测试一下
  434.     char str2[]="abcdefg";
  435.     insert(str1,str2,10);
  436.     puts(str1);
  437.     return 0;
  438. }
  439. /
  440. 9-8 
  441. int t_Update(T_ACCT_BALANCE table, int ACCT_BALANCE_ID, int BALANCE)
  442. {
  443.     T_ACCT_BALANCE tableUpdate;
  444. //  tableUpdate.SetConn(DefaultConnect);
  445. //  tableUpdate.SetBatSize(1);
  446. //  tableUpdate.SetTableName("ACCT_BALANCE_A");
  447.     
  448.     tableUpdate = table;    
  449.     tableUpdate.ACCT_BALANCE_ID = ACCT_BALANCE_ID;
  450.     tableUpdate.BALANCE = BALANCE;
  451.     long j = tableUpdate.Update();
  452.     if (j  > 0)
  453.     {
  454.         DefaultConnect.Commit();
  455.     }
  456.     else
  457.     {
  458.         j = -1;
  459.         DefaultConnect.Rollback();
  460.         cout << DefaultConnect.GetMsg();
  461.     }
  462.     return j;
  463. }
  464. 这样也是可以的
  465. 但是这个注释后却有问题,一个疑问
  466. int t_Update(T_ACCT_BALANCE table, int ACCT_BALANCE_ID, int BALANCE)
  467. {
  468. //  table.SetConn(DefaultConnect);
  469. //  table.SetBatSize(1);
  470. //  table.SetTableName("ACCT_BALANCE_A");
  471.     
  472.     table.ACCT_BALANCE_ID = ACCT_BALANCE_ID;
  473.     table.BALANCE = BALANCE;
  474.     long j = table.Update();
  475.     if (j > 0)
  476.     {
  477.         DefaultConnect.Commit();
  478.     }
  479.     else
  480.     {
  481.         j = -1;
  482.         DefaultConnect.Rollback();
  483.         cout << DefaultConnect.GetMsg();
  484.     }
  485.     return j;
  486. }
  487. 可能是形参修改了但是实参并没有改变
  488.     long j = Login("oracle");//(DB_CONF_HEAD);
  489.     if (j <= 0)
  490.     {
  491.         g_cLogFile.Error(0, "登录公用数据库失败,失败原因:[%s]!", GetMsg());
  492.         return -1;      
  493.     }
  494.     else
  495.     {
  496.         cout << "登录成功/n";
  497.     }
  498.     T_ACCT_BALANCE t_table;
  499.     t_table.SetConn(DefaultConnect);
  500.     t_table.SetBatSize(1);
  501.     t_table.SetTableName("ACCT_BALANCE_A");
  502.     j = t_table.Query(" balance < 2 and init_balance > 100");
  503. //  j = t_table.Query();
  504. //  t_table.Print();
  505.     if (j <= 0)
  506.     {
  507.         return 1;
  508.     }
  509.     int i = 0;
  510.     do {
  511.         cout << t_table.BALANCE.Float() << "    ";
  512.         cout << t_table.OPT_DATE.Char() << endl;
  513.         i++;
  514.     } while(t_table.Next() > 0 && i < 10);//
  515.     
  516.     t_table.ACCT_BALANCE_ID = 1;
  517.     t_table.PAYMENT_ID = 9;
  518.     t_table.ACCT_ID = 1;
  519.     t_table.SPE_PAYMENT_ID = 1;
  520.     t_table.BALANCE_TYPE_ID = 9;
  521.     t_table.INIT_BALANCE = 0;
  522.     t_table.BALANCE = 1;
  523.     t_table.EFF_DATE = "20080703203504";
  524.     t_table.EXP_DATE = "20080703203505";
  525.     t_table.OPT_DATE = "20080703203506";
  526.     t_table.REGION_ID = "A";
  527.     t_table.STAFF_ID = 0;
  528.     t_table.OPT_CODE = "A";
  529.     t_table.PAYED_PATH = "0";   
  530.     
  531.     T_ACCT_BALANCE b_table, c_table;
  532. //  t_Insert(t_table, 6, 1);
  533.     t_Update(t_table, 3, -1);
  534.     t_Delete(t_table, 6);
  535.     cout << t_table.BALANCE.Float() << endl;
  536.     
  537.     
  538.     Logout();
  539.     DefaultConnect.Commit();
  540.     DefaultConnect.Rollback();
  541. //
  542. 9-9
  543. 十叉树的查找操作
  544.   inline short Lookup( const char* p_index, TYPE*& pout )
  545.   {
  546.     T_NODE10 *m_pcursor  = m_proot;
  547.     short j = 1 ;
  548.     char c = '/0' ;
  549.     for( unsigned i = 0 ; i < strlen( p_index ) && j == 1 ; i ++ )
  550.     {
  551.       c = p_index[ i ] ;
  552.       if( m_pcursor -> p_pointer[ c - '0' ] != NULL )
  553.       {
  554.         m_pcursor = m_pcursor -> p_pointer[ c - '0' ] ;
  555.       }
  556.       else
  557.       {//已经到结尾了
  558.         j = 0 ;
  559.       }
  560.     } ;
  561.     if( j > 0 )
  562.     {
  563.       if( m_pcursor -> p_data )
  564.       {
  565.         pout =  m_pcursor -> p_data ;
  566.       }
  567.       else
  568.       {
  569.         pout = NULL ;
  570.         j = 0 ;
  571.         //Modify By June 20080725 出现此类情况可能正常,告警
  572.         g_cLogFile.Warn(0,  "节点值为空, INDEX=[%s]!", p_index ) ;
  573.       }
  574.     }
  575.     else
  576.       {
  577.       pout = NULL ;
  578.       }
  579.     return j ;
  580.   };
  581. //
  582.   /**
  583.    * 据电话号码查找出对应的区号,可用于电话号码区号的查询相类似的查询
  584.    * Add by Rose 2002-03-26
  585.    *
  586.    * @param p_index 号码
  587.    * @param pout 查询出的区号
  588.    * @return >0-查询成功 <=0-查询失败
  589.    */
  590.   inline short AreaLookup( const char* p_index, TYPE*& pout )
  591.   {
  592.     T_NODE10 *m_pcursor  = m_proot;
  593.     short j = 0;
  594.     char c = '/0';
  595.     pout = NULL;
  596.     for(unsigned i = 0; i < strlen(p_index); i++)
  597.     {
  598.       c = p_index[i];
  599.       if(m_pcursor->p_pointer[c-'0'] != NULL)
  600.       {
  601.         m_pcursor = m_pcursor->p_pointer[c - '0'];
  602.         if(m_pcursor->p_data) 
  603.         {
  604.           j = 1;
  605.           pout = m_pcursor->p_data;//这里进行了设置,但是并没有跳出循环,为超长的索引作准备,超长时,取前面的片段
  606.         }
  607.       }
  608.       else
  609.       {
  610.         if(m_pcursor->p_data)
  611.         {
  612.           pout = m_pcursor->p_data;
  613.           j = 1;
  614.         }
  615.         break;
  616.       }
  617.     }
  618.     return j ;
  619.   };
  620. 9-10
  621. 在使用自动生成工具时,要输入大写的名称,产生的文件在当前目录bin中
  622. cvs的使用,Update,可以先删除,再Update
  623. 9-11
  624. commit 将所有悬挂的修改保存
  625. RollBack 丢弃所有悬挂的修改
  626. 9-12
  627. 对生成的表进行测试
  628. /*  long j = Login("oracle");//(DB_CONF_HEAD);
  629.     if (j <= 0)
  630.     {
  631.         g_cLogFile.Error(0, "登录公用数据库失败,失败原因:[%s]!", GetMsg());
  632.         return -1;      
  633.     }
  634.     else
  635.     {
  636.         cout << "登录成功/n";
  637.     }
  638.     T_STUDENT t_table;
  639.     t_table.SetConn(DefaultConnect);
  640.     t_table.SetBatSize(1);
  641.     t_table.SetTableName("STUDENT");
  642.     j = t_table.Query();
  643. //  t_table.Print();
  644.     if (j <= 0)
  645.     {
  646.         return 1;
  647.     }
  648.     int i = 0;
  649.     do {
  650.         cout << t_table.SNAME.Char() << endl;
  651.         i++;
  652.     } while(t_table.Next() > 0 && i < 10);//    
  653. */  
  654.   /**
  655.    * 向数据管理类中添加索引
  656.    * @param ind 索引对象
  657.    */
  658.   void AddIndex(INDEX_BASE* ind)
  659.   {
  660.      ind_list.AddTail(ind);
  661.      ind->SetDbManager(this);
  662.   }
  663. /
  664. 加载的文件更新要及时,可能里面的错误没有更新
  665. 迈出了第一步
  666.     long j = Login("oracle");
  667.     if (j <= 0)
  668.     {
  669.         g_cLogFile.Error(0, "登录公用数据库失败,失败原因:[%s]!", GetMsg());
  670.         return 1;
  671.     }
  672.     
  673.     T_STUDENT t_student;
  674.     IND_STUDENT_BY_SNO ind_student_by_sno;
  675.     DB_STUDENT db_student;
  676.     db_student.AddIndex(&ind_student_by_sno);
  677.     db_student.SetTableName("STUDENT");
  678.     db_student.SetBatchSize(1);
  679.     db_student.LoadByTable(DefaultConnect, "");
  680.     STRU_STUDENT* stru_student;// = new STRU_STUDENT;
  681. //  if (stru_student == NULL)
  682. //  {
  683. //      cout << "NULL/n";
  684. //      return 1;
  685. //  }
  686.     ind_student_by_sno.Query("001", stru_student);
  687.     cout << stru_student->SNAME << endl;
  688.     
  689.     db_student.Remove();
  690.     ind_student_by_sno.RemoveAll();
  691.     long j = Login("oracle");
  692.     if (j <= 0)
  693.     {
  694.         g_cLogFile.Error(0, "登录公用数据库失败,失败原因:[%s]!", GetMsg());
  695.         return 1;
  696.     }
  697.     
  698.     T_STUDENT t_student;
  699.     IND_STUDENT_BY_SNO ind_student_by_sno;
  700.     DB_STUDENT db_student;
  701.     db_student.AddIndex(&ind_student_by_sno);
  702.     db_student.SetTableName("STUDENT");
  703.     db_student.SetBatchSize(1);
  704.     db_student.LoadByTable(DefaultConnect, "");
  705.     STRU_STUDENT* stru_student;// = new STRU_STUDENT;
  706.     ind_student_by_sno.Query("001", stru_student);
  707.     if (stru_student == NULL)
  708.     {
  709.         cout << "NULL/n";
  710.         return 1;
  711.     }
  712.     cout << stru_student->SNAME << endl;
  713.     //实现数据更新
  714.     strcpy(stru_student->SNAME, "Jam");
  715.     db_student.Update(stru_student);
  716.     //
  717.     
  718.     db_student.Save(DefaultConnect);
  719.     // 输出内存中的内容
  720.     T_LIST <STRU_STUDENT> *List_student = db_student.GetList();
  721. //  STRU_STUDENT* p = db_student.GetList()->GetHeadPosition()->pItem;
  722. //   = List_student->m_pHead->pItem;
  723.     List_student->GoHead();
  724.     while (List_student->Current() != NULL)
  725.     {
  726.         cout << List_student->Current()->SNAME << endl;
  727.         List_student->Next();
  728.     }
  729.     cout << db_student.GetNodeNumber() << endl;
  730.     
  731. //向内存中添加结点  
  732.     STRU_STUDENT* stru_stu = new STRU_STUDENT;
  733.     strcpy(stru_stu->SNO, "003");
  734.     strcpy(stru_stu->SNAME, "Google");
  735.     db_student.Insert(stru_stu);
  736.     db_student.Remove();
  737.     ind_student_by_sno.RemoveAll();
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值