嵌入式编程.pdf

上传人:奉*** 文档编号:4059581 上传时间:2021-01-13 格式:PDF 页数:10 大小:997.37KB
返回 下载 相关 举报
嵌入式编程.pdf_第1页
第1页 / 共10页
嵌入式编程.pdf_第2页
第2页 / 共10页
点击查看更多>>
资源描述

《嵌入式编程.pdf》由会员分享,可在线阅读,更多相关《嵌入式编程.pdf(10页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。

1、静态嵌入式,查询一个元组,localhost #include int main() EXEC SQL WHENEVER SQLWARNING SQLPRINT; EXEC SQL WHENEVER SQLERROR SQLPRINT; EXEC SQL CONNECT TO postgreslocalhost:5432 USER postgres USING 123456; EXEC SQL BEGIN DECLARE SECTION; int mm; char tt20=abcd; int yy; EXEC SQL END DECLARE SECTION; mm=2; yy=9; prin

2、tf(11mm=%d, tt=%s, yy=%d!n,mm,tt,yy); scanf(%d, printf(22mm=%d, tt=%s, yy=%d!n,mm,tt,yy); EXEC SQL SELECT eename,eeyear INTO :tt,:yy FROM public.exam WHERE eeid=:mm; EXEC SQL DISCONNECT; printf(33mm=%d, tt=%s, yy=%d!n,mm,tt,yy); return 0; 静态嵌入式,IP 链接,修改 #include int main() EXEC SQL WHENEVER SQLWARNI

3、NG SQLPRINT; EXEC SQL WHENEVER SQLERROR SQLPRINT; EXEC SQL CONNECT TO postgres192.168.1.101:5432 USER postgres USING 123456; EXEC SQL BEGIN DECLARE SECTION; int mm; char tt20=abcd; int yy; EXEC SQL END DECLARE SECTION; mm=2; yy=9; printf(11mm=%d, tt=%s, yy=%d!n,mm,tt,yy); scanf(%d, printf(22mm=%d, t

4、t=%s, yy=%d!n,mm,tt,yy); EXEC SQL SELECT eename,eeyear INTO :tt,:yy FROM public.exam WHERE eeid=:mm; printf(33mm=%d, tt=%s, yy=%d!n,mm,tt,yy); EXEC SQL UPDATE public.exam SET eeyear=eeyear+2000 WHERE eeid=:mm; EXEC SQL SELECT eename,eeyear INTO :tt,:yy FROM public.exam WHERE eeid=:mm; printf(44mm=%d

5、, tt=%s, yy=%d!n,mm,tt,yy); EXEC SQL UPDATE public.exam SET eeyear=eeyear-2000 WHERE eeid=:mm; EXEC SQL SELECT eename,eeyear INTO :tt,:yy FROM public.exam WHERE eeid=:mm; printf(55mm=%d, tt=%s, yy=%d!n,mm,tt,yy); EXEC SQL DISCONNECT; printf(66mm=%d, tt=%s, yy=%d!n,mm,tt,yy); return 0; Cursor,循环取元组 #

6、include int main() EXEC SQL WHENEVER SQLWARNING SQLPRINT; EXEC SQL WHENEVER SQLERROR SQLPRINT; EXEC SQL CONNECT TO postgres192.168.1.101:5432 USER postgres USING 123456; EXEC SQL BEGIN DECLARE SECTION; int mm; char tt20=abcd; int yy; EXEC SQL END DECLARE SECTION; mm=189; yy=9; EXEC SQL DECLARE query

7、c CURSOR FOR SELECT eeid,eename,eeyear FROM public.exam ; printf(11mm=%d, tt=%s, yy=%d!n,mm,tt,yy); EXEC SQL OPEN queryc; do EXEC SQL FETCH FROM queryc INTO :mm,:tt,:yy; if (!strcmp(SQLSTATE,02000)break; printf(66mm=%d, tt=%s, yy=%d!n,mm,tt,yy); while (strcmp(SQLSTATE,02000); EXEC SQL DISCONNECT; pr

8、intf(88mm=%d, tt=%s, yy=%d!n,mm,tt,yy); return 0; Scroll cursor 自由滑动 #include int main() EXEC SQL WHENEVER SQLWARNING SQLPRINT; EXEC SQL WHENEVER SQLERROR SQLPRINT; EXEC SQL CONNECT TO postgres192.168.1.101:5432 USER postgres USING 123456; EXEC SQL BEGIN DECLARE SECTION; int mm; char tt20=abcd; int

9、yy; int i=0; EXEC SQL END DECLARE SECTION; EXEC SQL DECLARE querycc SCROLL CURSOR FOR SELECT eeid,eename,eeyear FROM public.exam ; EXEC SQL OPEN querycc; do i=i+1; EXEC SQL FETCH FROM querycc INTO :mm,:tt,:yy; if (!strcmp(SQLSTATE,02000)break; printf(%d%dmm=%d, tt=%s, yy=%d!n,i,i,mm,tt,yy); while (s

10、trcmp(SQLSTATE,02000); EXEC SQL DECLARE queryc SCROLL CURSOR FOR SELECT eeid,eename,eeyear FROM public.exam ; EXEC SQL OPEN queryc; EXEC SQL FETCH NEXT FROM queryc INTO :mm,:tt,:yy; if (strcmp(SQLSTATE,02000) printf(NEXTmm=%d, tt=%s, yy=%d!n,mm,tt,yy); EXEC SQL FETCH LAST FROM queryc INTO :mm,:tt,:y

11、y; if (strcmp(SQLSTATE,02000) printf(LASTmm=%d, tt=%s, yy=%d!n,mm,tt,yy); EXEC SQL FETCH NEXT FROM queryc INTO :mm,:tt,:yy; if (strcmp(SQLSTATE,02000) printf(NEXTmm=%d, tt=%s, yy=%d!n,mm,tt,yy); EXEC SQL FETCH FIRST FROM queryc INTO :mm,:tt,:yy; if (strcmp(SQLSTATE,02000) printf(FIRSTmm=%d, tt=%s, y

12、y=%d!n,mm,tt,yy); EXEC SQL FETCH NEXT FROM queryc INTO :mm,:tt,:yy; if (strcmp(SQLSTATE,02000) printf(NEXTmm=%d, tt=%s, yy=%d!n,mm,tt,yy); EXEC SQL FETCH relative -1 FROM queryc INTO :mm,:tt,:yy; if (strcmp(SQLSTATE,02000) printf(-1mm=%d, tt=%s, yy=%d!n,mm,tt,yy); EXEC SQL FETCH relative -2 FROM que

13、ryc INTO :mm,:tt,:yy; if (strcmp(SQLSTATE,02000) printf(-2mm=%d, tt=%s, yy=%d!n,mm,tt,yy); EXEC SQL FETCH relative -2 FROM queryc INTO :mm,:tt,:yy; if (strcmp(SQLSTATE,02000) printf(-2mm=%d, tt=%s, yy=%d!n,mm,tt,yy); EXEC SQL FETCH FIRST FROM queryc INTO :mm,:tt,:yy; if (strcmp(SQLSTATE,02000) print

14、f(FIRSTmm=%d, tt=%s, yy=%d!n,mm,tt,yy); EXEC SQL FETCH LAST FROM queryc INTO :mm,:tt,:yy; if (strcmp(SQLSTATE,02000) printf(LASTmm=%d, tt=%s, yy=%d!n,mm,tt,yy); EXEC SQL CLOSE querycc; EXEC SQL CLOSE queryc; EXEC SQL DISCONNECT; return 0; 动态构造 pgSQL 语句,对数据进行更新。 #include int main() EXEC SQL WHENEVER

15、SQLWARNING SQLPRINT; EXEC SQL WHENEVER SQLERROR SQLPRINT; EXEC SQL CONNECT TO postgres192.168.1.101:5432 USER postgres USING 123456; EXEC SQL BEGIN DECLARE SECTION; char *tt=update exam set eeyear=eeyear+? where eeid=?; char *ttc=commit; int ii=199;int jj=20000; EXEC SQL END DECLARE SECTION; EXEC SQ

16、L PREPARE mmtt from :tt; EXEC SQL EXECUTE mmtt USing :jj,:ii; EXEC SQL EXECUTE IMMEDIATE :ttc; EXEC SQL DISCONNECT; return 0; 执行前数据库状态: 执行后数据库状态: 如果定义了SCROLL,那么游标可以向后滚动;如果定义了NO SCROLL,那么向后取的动作 会被拒绝; 如果二者都没有定义,那么是否进行向后取的动作会根据查询来判断。 执行从键盘输入的一个 pgSQL 语句,查询一个数据项。 #include int main() EXEC SQL WHENEVER SQ

17、LWARNING SQLPRINT; EXEC SQL WHENEVER SQLERROR SQLPRINT; EXEC SQL CONNECT TO postgres192.168.1.101:5432 USER postgres USING 123456; EXEC SQL BEGIN DECLARE SECTION; char *tt,str100; int ii,jj; EXEC SQL END DECLARE SECTION; tt=str; scanf(%n,tt); printf(%sn,tt); printf(qqqqqn,tt); EXEC SQL PREPARE mystmt FROM :tt; EXEC SQL EXECUTE mystmt INTO :ii; printf(eeyear=%d,ii); EXEC SQL DISCONNECT; return 0;

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 教育专区 > 大学资料

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号© 2020-2023 www.taowenge.com 淘文阁