上海交通大学:《数据库系统原理 The principle of Database System》课程教学资源(课件讲稿)chapter9 SQL in a server environment

Chapter 9 SQL in a server environment SQL in a Programming Environment embedded SQL persistent stored modules Database-Connection Libraries Call-level interface (CLI) JDBC PHP
Chapter 9 SQL in a server environment SQL in a Programming Environment embedded SQL persistent stored modules Database-Connection Libraries Call-level interface (CLI) JDBC PHP

SQL in Real Programs We have seen only how SQL is used at the generic query interface --an environment where we sit at a terminal and ask queries of a database. Reality is almost always different: conventional programs interacting with SQL
SQL in Real Programs We have seen only how SQL is used at the generic query interface --- an environment where we sit at a terminal and ask queries of a database. Reality is almost always different: conventional programs interacting with SQL

Options 1.SQL statements are embedded in a host language (e.g.,C). 2. Code in a specialized language is stored in the database itself (e.g., PSM,PL/SQL). 3. Connection tools are used to allow a conventional language to access a database (e.g.,CLI,JDBC,PHP/DB)
Options 1. SQL statements are embedded in a host language (e.g., C). 2. Code in a specialized language is stored in the database itself (e.g., PSM, PL/SQL). 3. Connection tools are used to allow a conventional language to access a database (e.g., CLI, JDBC, PHP/DB)

SQL in a Programming Environment Embedded SOL:add to a conventional programming language(C for example, we called host language )certain statements that represent SQL operation Host language+embedded SQL> code?
SQL in a Programming Environment Embedded SQL: add to a conventional programming language (C for example, we called host language ), certain statements that represent SQL operation. Host language+embedded SQL Æ code?

System Implementation Host Language Embedded SQL Preprocessing Host Language Function calls Host-language compiler SQL library Object-code program How to identify SQL statements? How to move data between SQL and a conventional programming language? Mismatch problem exists?
System Implementation How to identify SQL statements? How to move data between SQL and a conventional programming language? Mismatch problem exists? Host Language + Embedded SQL Preprocessing Host Language + Function calls Host-language compiler SQL library Object-code program

How to recognize SOL statements (the Interface between SOL statements and programming language) Each embedded SOL statement introduced with EXEC SQL ■ Shared variables exchange data between SQL and a host language.When they are referred by a SQL statement,these shared variables are prefixed by a colon,but they appear without colon in host- language statements. EXEC SOL BEGIN /END DECLARE SECTION to declare shared variables
How to recognize SQL statements (the Interface between SQL statements and programming language) Each embedded SQL statement introduced with EXEC SQL Shared variables : exchange data between SQL and a host language. When they are referred by a SQL statement, these shared variables are prefixed by a colon, but they appear without colon in hostlanguage statements. EXEC SQL BEGIN / END DECLARE SECTION to declare shared variables

the Interface between SOL statements and programming language SOL define an array of characters SQLSTATE that is set every time the system is called. ■ SOLSTATE connects the host-language program with the SQL execution system. 00000:no error √02000:could not be found
the Interface between SQL statements and programming language SQL define an array of characters SQLSTATE that is set every time the system is called. SQLSTATE connects the host-language program with the SQL execution system. 9 00000: no error 9 02000: could not be found

Implementations of SQLSTATE SQL defines an array of characters SQLSTATE that is set every time the system is called. Errors are signaled there Different systems use different way Oracle provides us with a header file sqlca.h that declares a communication area and defines macros to access it,such as NOT FOUND. Sybase provides SQLCA with sqlcode 0:success,<0:fail,100:not found
Implementations of SQLSTATE SQL defines an array of characters SQLSTATE that is set every time the system is called. Errors are signaled there Different systems use different way Oracle provides us with a header file sqlca.h that declares a communication area and defines macros to access it, such as NOT FOUND. Sybase provides SQLCA with sqlcode 0:success, <0: fail, 100: not found

Example:Find the price for a given beer at a given bar Sells (bar,beer,price) EXEC SOL BEGIN DECLARATION SECTION CHAR theBar[21],theBeer[21]; Float thePrice; EXEC SOL END DECLARAE SECTION EXEC SQL SELECT price INTO thePrice FROM sells WHERE beer =theBeer AND bar =theBar;
Example: Find the price for a given beer at a given bar Sells (bar, beer, price) EXEC SQL BEGIN DECLARATION SECTION CHAR theBar[21], theBeer[21]; Float thePrice; EXEC SQL END DECLARAE SECTION EXEC SQL SELECT price INTO :thePrice FROM sells WHERE beer = :theBeer AND bar =:theBar ;

Queries produce sets of tuples as a result,while none of the major host languages supports a set data type directly.So,cursors are used. A cursor declaration:EXEC SOL DECLARE CURSOR FOR A statement EXEC SOL OPEN:the cursor is ready to retrieve the first tuple of the relation over which the cursor ranges. EXEC SOL FETCH FROM EXEC SOL CLOSE :the cursor is no longer ranges over tuples of the relation
Queries produce sets of tuples as a result, while none of the major host languages supports a set data type directly. So, cursors are used. A cursor declaration: EXEC SQL DECLARE CURSOR FOR A statement EXEC SQL OPEN : the cursor is ready to retrieve the first tuple of the relation over which the cursor ranges. EXEC SQL FETCH FROM INTO EXEC SQL CLOSE : the cursor is no longer ranges over tuples of the relation
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
- 上海交通大学:《微机原理与接口技术》课程教学资源(课件讲稿)第二章 8086系统结构.pdf
- 上海交通大学:《微机原理与接口技术》课程教学资源(课件讲稿)第一章 微机原理与接口技术绪论(朱兰娟).pdf
- 上海交通大学:《微机原理与接口技术》课程教学资源(课件讲稿)第十四章 MCS-51单片机(2/2).pdf
- 上海交通大学:《微机原理与接口技术》课程教学资源(课件讲稿)第十四章 MCS-51单片机(1/2).pdf
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Recitation Notes_Recitation X.ppt
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Recitation Notes_Recitation VIII.ppt
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Recitation Notes_Recitation VII.ppt
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Recitation Notes_Recitation V.ppt
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Recitation Notes_Recitation IX.ppt
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Recitation Notes_recitation 13.pdf
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Recitation Notes_Recitation 1.ppt
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Lecture Notes_vector_string.pdf
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Lecture Notes_Start with C plusplus.pdf
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Lecture Notes_Random Number_Graphics.pdf
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Lecture Notes_programming style guide for C plusplus.pdf
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Lecture Notes_objects and classes.pdf
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Lecture Notes_Introduction to Vg101.pdf
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Lecture Notes_Introduction to Computer and Programming.pdf
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Lecture Notes_Function.pdf
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Lecture Notes_files_DataBase Design.pdf
- 上海交通大学:《程序设计基础》课程教学资源(习题集)05年期末习题_Pointer Review Solution.pdf
- 上海交通大学:《程序设计基础》课程教学资源(习题集)05年期末习题_Pointer Review.pdf
- 上海交通大学:《程序设计基础》课程教学资源(习题集)05年期末习题_Practice Final 1.pdf
- 上海交通大学:《程序设计基础》课程教学资源(习题集)05年期末习题_practice Final 2.pdf
- 上海交通大学:《程序设计基础》课程教学资源(习题集)05年期末习题_practice Final 3.pdf
- 上海交通大学:《程序设计基础》课程教学资源(习题集)05年期末习题_Solution for Practice Final 1.pdf
- 上海交通大学:《程序设计基础》课程教学资源(习题集)05年期末习题_Solution for Practice Final 2.pdf
- 上海交通大学:《程序设计基础》课程教学资源(习题集)C++语言_I.运算符重载.pdf
- 上海交通大学:《程序设计基础》课程教学资源(习题集)C++语言_II.继承与派生.pdf
- 上海交通大学:《程序设计基础》课程教学资源(习题集)C++语言_III.多态性.pdf
- 上海交通大学:《程序设计基础》课程教学资源(习题集)C++语言_IV.异常处理与模板.pdf
- 上海交通大学:《程序设计基础》课程教学资源(习题集)C++语言_V. 流库.pdf
- 上海交通大学:《程序设计基础》课程教学资源(习题集)C++语言_VI.类与对象.pdf
- 上海交通大学:《程序设计基础》课程教学资源(习题集)C++语言_VII.类与对象的高级操作.pdf
- 上海交通大学:《程序设计基础》课程教学资源(习题集)C语言_I.C语言概述.pdf
- 上海交通大学:《程序设计基础》课程教学资源(习题集)C语言_II.基本数据类型和运算.pdf
- 上海交通大学:《程序设计基础》课程教学资源(习题集)C语言_III.流程控制.pdf
- 上海交通大学:《程序设计基础》课程教学资源(习题集)C语言_IV.函数和程序结构.pdf
- 上海交通大学:《程序设计基础》课程教学资源(习题集)C语言_IX.文件.pdf
- 上海交通大学:《程序设计基础》课程教学资源(习题集)C语言_V.数组.pdf