Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1049227
  • 博文数量: 573
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 66
  • 用 户 组: 普通用户
  • 注册时间: 2016-06-28 16:21
文章分类

全部博文(573)

文章存档

2018年(3)

2016年(48)

2015年(522)

分类: C/C++

2015-12-02 19:37:08

main.ec文件

点击(此处)折叠或打开

  1. #include <string.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>

  4. EXEC SQL define NAMELEN 60;
  5. EXEC SQL define COMPLEN 80;
  6. EXEC SQL define ADDRLEN 10;

  7. EXEC SQL INCLUDE SQLCA;

  8. char * myTrim(char * str) /*去掉字符串首尾*/
  9. {
  10.     if(NULL == str)
  11.     {
  12.         return NULL;
  13.     }
  14.     char * head = str;
  15.     char * tail = str + strlen(str) -1;
  16.     while((*head == ' ')&&(head < tail))head++;
  17.     while((*tail == ' ')&&(tail > head))tail--;
  18.     *(tail + 1) = '\0';
  19.     memcpy(str, head, sizeof(char) * (tail - head + 2));
  20.     return str;
  21. }

  22. int main(int argc, char ** argv)
  23. {
  24.     EXEC SQL BEGIN DECLARE SECTION;
  25.     char name[NAMELEN];
  26.     char comp[COMPLEN];
  27.     char addr[ADDRLEN];
  28.     int age = 0;
  29.     double amt = 0.00;
  30.     int nameind = -2;
  31.     int addrind = -2;
  32.     int compind = -2;
  33.     int ageind = -2;
  34.     int amtind = -2;
  35.     EXEC SQL END DECLARE SECTION;
  36.     
  37.     memset(name, '\0', sizeof(name));
  38.     memset(comp, '\0', sizeof(comp));
  39.     memset(addr, '\0', sizeof(addr));

  40.     EXEC SQL CONNECT TO "dbtbank";
  41.     if(0 != sqlca.sqlcode)
  42.     {
  43.         printf("connect err! sqlcode = [%d]\n",sqlca.sqlcode);
  44.         return -1;
  45.     }

  46.     EXEC SQL select lname, address, company, age, amt
  47.     into :name indicator :nameind, :addr indicator addrind, :comp indicator :compind, :age indicator :ageind, :amt indicator :amtind
  48.     from customer where custid = '108';
  49.     if(0 != sqlca.sqlcode)
  50.     {
  51.         printf("select err! sqlcode = [%d]\n", sqlca.sqlcode);
  52.         return -1;
  53.     }
  54.     myTrim(name);
  55.     myTrim(comp);
  56.     printf("name = [%s]\n", name);
  57.     printf("addr = [%s]\n", addr);
  58.     printf("comp = [%s]\n", comp);
  59.     printf("age = [%d]\n", age);
  60.     printf("amt = [%f]\n", amt);
  61.     printf("amt = [%d]\n", amt);
  62.     printf("nameind = [%d]\n", nameind);
  63.     printf("addrind = [%d]\n", addrind);
  64.     printf("compind = [%d]\n", compind);
  65.     printf("ageind = [%d]\n", ageind);
  66.     printf("amtind = [%d]\n", amtind);
  67.     return 0;
  68. }
customer.txt文件

点击(此处)折叠或打开

  1. 105|wangxiancai|hubei|tienon|25|105.23|
  2. 106|zzzzzhhhhhaaaaannnnnggggg|hubeijingzho|llllliiiiiaaaaannnnn|24|100.0|
  3. 107| | | |0|0.0|
  4. 108||hubeijingzho|hua|||
  5. 109|wangxc|||||
  6. 110||||||
customer_create.sql文件

点击(此处)折叠或打开

  1. dbaccess dbtbank <<!
  2. drop table customer;
  3. create table customer
  4. (
  5.     custid int primary key,
  6.     lname char(30),
  7.     address char(12),
  8.     company char(36),
  9.     age int,
  10.     amt decimal(10,2)
  11. );
  12. !
customer_delete.sql文件

点击(此处)折叠或打开

  1. dbaccess dbtbank <<!
  2. delete from customer;
  3. !
customer_insert.sql文件

点击(此处)折叠或打开

  1. dbaccess dbtbank <<!
  2. insert into customer values('105', 'wangxiancai', 'hubei', 'tienon', 25, 105.23);
  3. insert into customer values('106', 'zzzzzhhhhhaaaaannnnnggggg','hubeijingzhoujianli', 'llllliiiiiaaaaannnnn', 24, 100);
  4. insert into customer values('107', ' ', ' ', ' ', 0, 0.00);
  5. insert into customer(custid, address, company) values('108','hubeijingzhoujianli', 'hua');
  6. insert into customer(custid, lname) values('109', 'wangxc');
  7. insert into customer(custid) values('110');
  8. insert into customer values('112', 'yangmeixue', 'hubei', 'huaxin', 26, 1100.5);
  9. !
customer_select.sql文件

点击(此处)折叠或打开

  1. dbaccess dbtbank <<!
  2.  select * from customer where lname like 'yang%';
  3. !
customer_unload.sql文件

点击(此处)折叠或打开

  1. dbaccess dbtbank <<!
  2. unload to customer.txt select * from customer;
  3. !
customer_update.sql文件

点击(此处)折叠或打开

  1. dbaccess dbtbank <<!
  2. update customer set lname='yangmeixue_pig' where lname='yangmeixue'
  3. !

阅读(712) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~