12 Embedding SQL in Programming languages



Similar documents
12 Embedding SQL in Programming languages

Chapter 13. Introduction to SQL Programming Techniques. Database Programming: Techniques and Issues. SQL Programming. Database applications

More SQL: Assertions, Views, and Programming Techniques

SQL and Programming Languages. SQL in Programming Languages. Applications. Approaches

Chapter 9, More SQL: Assertions, Views, and Programming Techniques

Embedded SQL. Unit 5.1. Dr Gordon Russell, Napier University

Programming Database lectures for mathema

SQL is capable in manipulating relational data SQL is not good for many other tasks

SQL: Programming. Introduction to Databases CompSci 316 Fall 2014

CS346: Database Programming.

Oracle SQL, introduced in the previous chapter, is not a language that can be

Introduction. Introduction: Database management system. Introduction: DBS concepts & architecture. Introduction: DBS versus File system

Database Access via Programming Languages

Introduction: Database management system

Embedding SQL in High Level Language Programs

1 File Processing Systems

Goals. Managing Multi-User Databases. Database Administration. DBA Tasks. (Kroenke, Chapter 9) Database Administration. Concurrency Control

Transactions and Concurrency Control. Goals. Database Administration. (Manga Guide to DB, Chapter 5, pg , ) Database Administration

Course Objectives. Database Applications. External applications. Course Objectives Interfacing. Mixing two worlds. Two approaches

Mimer SQL. Programmer s Manual. Version 8.2 Copyright 2000 Mimer Information Technology AB

Database Access from a Programming Language: Database Access from a Programming Language

Database Access from a Programming Language:

What is ODBC? Database Connectivity ODBC, JDBC and SQLJ. ODBC Architecture. More on ODBC. JDBC vs ODBC. What is JDBC?

Introduction to Database Management Systems

Transaction Management Overview

Week 1 Part 1: An Introduction to Database Systems. Databases and DBMSs. Why Use a DBMS? Why Study Databases??

Real SQL Programming 1

Database Programming. Week *Some of the slides in this lecture are created by Prof. Ian Horrocks from University of Oxford

Embedded SQL programming

KB_SQL Programmer s Reference Guide

SQL/PSM. Outline. Database Application Development Oracle PL/SQL. Why Stored Procedures? Stored Procedures PL/SQL. Embedded SQL Dynamic SQL

Database Tuning and Physical Design: Execution of Transactions

Database Programming with PL/SQL: Learning Objectives

CS 377 Database Systems SQL Programming. Li Xiong Department of Mathematics and Computer Science Emory University

Statement Level Interface. Call Level Interface. Static SQL. Status. Connections. Transactions. To connect to an SQL database, use a connect statement

The first time through running an Ad Hoc query or Stored Procedure, SQL Server will go through each of the following steps.

Concurrency Control: Locking, Optimistic, Degrees of Consistency

Week 5: Embedded SQL. Embedded SQL 4. Application Program. Interactive vs. Non-Interactive SQL. Update Statements

Darshan Institute of Engineering & Technology PL_SQL

ODBC Chapter,First Edition

JDBC (Java / SQL Programming) CS 377: Database Systems

Chapter 6 The database Language SQL as a tutorial

PL/SQL. Database Procedural Programming PL/SQL and Embedded SQL. Procedures and Functions

Using SQL in RPG Programs: An Introduction

Introduction to PL/SQL Programming

Performance Implications of Various Cursor Types in Microsoft SQL Server. By: Edward Whalen Performance Tuning Corporation

Objectives. Distributed Databases and Client/Server Architecture. Distributed Database. Data Fragmentation

TRANSACÇÕES. PARTE I (Extraído de SQL Server Books Online )

Database programming 20/08/2015. DBprog news. Outline. Motivation for DB programming. Using SQL queries in a program. Using SQL queries in a program

Teradata Database. SQL Reference. Stored Procedures and Embedded SQL

The ConTract Model. Helmut Wächter, Andreas Reuter. November 9, 1999

Real SQL Programming. Persistent Stored Modules (PSM) PL/SQL Embedded SQL

SQL and programming languages

Transactions and the Internet

ICOM 6005 Database Management Systems Design. Dr. Manuel Rodríguez Martínez Electrical and Computer Engineering Department Lecture 2 August 23, 2001

Unit 12 Database Recovery

MyOra 3.0. User Guide. SQL Tool for Oracle. Jayam Systems, LLC

Oracle Database: SQL and PL/SQL Fundamentals

Choosing a Data Model for Your Database

What Is Specific in Load Testing?

D61830GC30. MySQL for Developers. Summary. Introduction. Prerequisites. At Course completion After completing this course, students will be able to:

SQL Programming. CS145 Lecture Notes #10. Motivation. Oracle PL/SQL. Basics. Example schema:

SQL Injection. The ability to inject SQL commands into the database engine through an existing application

14 Triggers / Embedded SQL

Informatica e Sistemi in Tempo Reale

Firebird. Embedded SQL Guide for RM/Cobol

Introduction to Database Systems. Chapter 1 Introduction. Chapter 1 Introduction

Duration Vendor Audience 5 Days Oracle End Users, Developers, Technical Consultants and Support Staff

Persistent Stored Modules (Stored Procedures) : PSM

Oracle Database: SQL and PL/SQL Fundamentals

Oracle Database: SQL and PL/SQL Fundamentals NEW

The JAVA Way: JDBC and SQLJ

Stored Routines in Transactional Context

SQL Databases Course. by Applied Technology Research Center. This course provides training for MySQL, Oracle, SQL Server and PostgreSQL databases.

Oracle Database: SQL and PL/SQL Fundamentals NEW

Sources: On the Web: Slides will be available on:

Transactions and Recovery. Database Systems Lecture 15 Natasha Alechina

Lecture 7: Concurrency control. Rasmus Pagh

Database Migration from MySQL to RDM Server

InterBase 6. Embedded SQL Guide. Borland/INPRISE. 100 Enterprise Way, Scotts Valley, CA

Guide to SQL Programming: SQL:1999 and Oracle Rdb V7.1

COMP5426 Parallel and Distributed Computing. Distributed Systems: Client/Server and Clusters

Database System Architecture & System Catalog Instructor: Mourad Benchikh Text Books: Elmasri & Navathe Chap. 17 Silberschatz & Korth Chap.

Elena Baralis, Silvia Chiusano Politecnico di Torino. Pag. 1. Active database systems. Triggers. Triggers. Active database systems.

SQL Basics for RPG Developers

5. CHANGING STRUCTURE AND DATA

The C Programming Language course syllabus associate level

Lesson 4 Web Service Interface Definition (Part I)

Application Development Guide: Programming Server Applications

Topics Advanced PL/SQL, Integration with PROIV SuperLayer and use within Glovia

Using ORACLE in the CSLab

PL/SQL Programming Workbook

Client Server Architecture

Intro to Embedded SQL Programming for ILE RPG Developers

SQL Server Database Coding Standards and Guidelines

Objectives. Chapter 2: Operating-System Structures. Operating System Services (Cont.) Operating System Services. Operating System Services (Cont.

Chapter 9 Java and SQL. Wang Yang wyang@njnet.edu.cn

Transcription:

12 Embedding SQL in Programming languages 12.1 Introduction: using SQL from programs 12.2 Embedded SQL 12.2.1 Static and dynamic embedding 12.2.2 Cursors 12.2. 3. ESQL / C 12.2. 4 Positioned Update 12.3 Transactions in application programs 12.3.1 Definition 12.3.2 Isolation levels 12.4 SQL and Java 12.4.1 JDBC 12.4.2 SQLJ Kemper / Eickler: chap. 4.19-4.23; Melton: chap. 12,13,17-19, Widom, Ullman, Garcia-Molina: chapt.8 Christian Ullenboom Java ist auch eine Insel, Kap. 20, Galileo Comp. Using SQL from Programs Introduction SQL is a data sublanguage Needs a host language Control structures User interface: output formatting, forms Transactions: more than one DB interaction as a unit of work Issues Language mismatch ("impedance mismatch") Set oriented operations versus manipulation of individuals How to interconnect program variables and e.g attributes in SQL statements? Should an SQL-statement as part of a program be compiled, when? Question: could you imagine a language bringing both worlds together? HS / DBS05-15-ProgLang 2

Three-tier architecture (example) GUI client Web browser Web browser DB client Middleware layer Web Server Middle tier DB Application DB Application File System DB-Server DB-Server DB-Server HS / DBS05-15-ProgLang 3 Using SQL from Programs Introduction Overview of language / DB integration concepts "Fourth Generation Languages" Module Language --> PSM ( ~ PL/SQL, PLpgSQL) Standardized in SQL-99 Interface of standard programming languages Call level interface, proprietary library routines, API Standardized: SQL CLI Open Database connection (ODBC), Embedded C / Java /.. Standardized language extensions Standardized API Java DBC "Fourth generation Language" Stored Procedures C / Java / Perl / Python,... Component architectures: hiding the details of DB interaction, Enterprise Java Beans (EJB) HS / DBS05-15-ProgLang 4

SQL from Programs"4. Generation Languages" Proprietary "Fourth generation language (4GL)" Underlying assumption: most application programs are algorithmically simple sophisticated output formatting needed it should be difficult for users to switch from one DBS to another Technical concept Client DBS Proprietary protocol Client evolved from simple Terminal to 4GL-Interpreter Open systems movement and HTTP / HTML / Java makes 4GL less important HS / DBS05-15-ProgLang 5 Using SQL from Programs Modules Standardization efforts (SQL 89 / SQL 99) Modules and Embedded SQL SQL Modules Separate parameterized Modules of SQL statements Compiled for a particular language (e.g. COBOL, C, ADA...) Linked to application program (statically?) Disadvantage SQL code hidden in application and vice versa Not widely used Superseded by flexible stored procedure concept HS / DBS05-15-ProgLang 6

Using SQL from Programs Call interface Call level interface Language and DBS specific library of procedures to access the DB Example: MySQL C API Communication buffer for transfering commands and results API data types like MYSQL handle for db connections MYSQL_RES structure which represents result set API functions mysql_real_query() mysql_real_query (MYSQL *mysql, const char * query, unsigned int length) query of length of character string in buffer and many more... Standard : Open Database Connection (ODBC) Predecessor of Java Database Connection (JDBC), see below HS / DBS05-15-ProgLang 7 SQL Call level interface (SQL/CLI) Standardized Interface to C / C++ defined by X/OPEN and SQL Accesss group Main advantages DBS-independent Application development independent from DBS (as opposed to Embedded SQL precompiler approach, see below) Easy to connect to multiple DB Microsoft implementation ODBC (= Open Database Connectivity) de facto standard, available not only for MS products HS / DBS05-15-ProgLang 8

Main cycle of transaction execution with SQL/CLI Calls are embedded in the application program See also JDBC, ESQL source: IBM DB2 manual 12.2 Embedded SQL Embedded SQL the most important(?) approach Concepts Program consists of "native" and SQL-like statements Precompiler compiles it to native code, includes calls to DBS resources Employs call level interface in most implementations Most popular: Embedded C (Oracle: PRO*C) ESQL Precompiler Native Language code Compiler Object code Linker Excecutable SQLJ = Embedded Java Library HS / DBS05-15-ProgLang 10

Embedded SQL (ESQL) Syntax and more Well defined type mapping (for different languages) Exception handling (WHENEVER condition action) SQLSTATE, SQLCODE (deprecated) Syntax for embedded SQL statements Binding to host language variables #sql {SELECT m# FROM M WHERE titel = :titlestring};}... #sql {FETCH...INTO :var1} hypothetical syntax, like SQLJ HS / DBS05-15-ProgLang 11 ESQL C / Java embedding ESQL/C EXEC SQL UPDATE staff SET job = 'Clerk' WHERE job = 'Mgr'; if ( SQLCODE < 0 printf( "Update Error:... ); SQLJ try { #sql { UPDATE staff SET job = 'Clerk' WHERE job = 'Mgr' }; } catch (SQLException e) { println( "Update Error: SQLCODE = " +... ); HS / DBS05-15-ProgLang 12

ESQL code generation Code generated basically at compile time. DBS and DB must be known before runtime in order to generate executables from: DB2 manual HS / DBS05-15-ProgLang 13 12.2.1 ESQL Static / dynamic embedding Static versus dynamic SQL: Static: all SQL commands are known in advance, SQL-compilation and language binding at precompile time Dynamic (i) SQL-String executed by DBS: Operator tree, optimization, code binding... (ii) SQL-String prepared (compiled) at runtime. Performance gain in loops etc. HS / DBS05-15-ProgLang 14

12.2.2 ESQL Cursors Cursor concept How to process a result set one tuple after the other? CURSOR: name of an SQL statement and a handle for processing the result set record by record Cursor is defined, opened at runtime (= SQL-statement is excecuted) and used for FETCHing single result records DECLARE c.. OPEN c FETCH c c DBS Cursor concept used in most language embeddings of SQL (ESQL-C, PL/SQL, JDBC and more) Buffers for application program cursors DBS may determine result set in a lazy or eager way HS / DBS05-15-ProgLang 15 ESQL Cursors Explicit cursors: Declared and named by the programmer Sometimes implicit cursors for individual SQL statements are used in 4GL Cursor assigns a name to an SQL statement. Cursor / SQL statement do not bind the result attributes to variables allows to traverse the result set (the "active set" ) row by row Declare curs for Select c#, lname, m.title from C, R, M where... Active set Cursor curs 7369 SMITH To be or.. 7566 JONES Metropolis 7788 SCOTT Forest Gump 7876 ADAMS Forest Gump 7902 FORD Star Wars I Current row HS / DBS05-15-ProgLang 16

ESQL Cursors Controlling a cursor: the necessary steps No DECLARE OPEN FETCH EMPTY? Yes CLOSE Create a named SQL area Identify the active set Load the current row into variables Test for existing rows Release the active set Executes the query HS / DBS05-15-ProgLang 17 ESQL Cursors Opening OPEN cursor_name; In a compiled language environment (e.g. embedded C): bindinput variables executequery put (first) results into communication (context) area no exception if result is empty has to be checked when fetching the results positions the cursor before the first row of the result set (" 1 ") First steps in an interpreted language (e.g. 4GL PL/SQL) : allocate context area parse query HS / DBS05-15-ProgLang 18

ESQL Cursors Fetch FETCH curs INTO :x, :namevar,, ::titlevar; Cursor scrolling (Declare c SCROLL cursor.. in SQL 92): FETCH [NEXT PRIOR FIRST LAST [ABSOLUTE RELATIVE expression] ] FROM cursor INTO target-variables = FETCH curs PRIOR INTO :x, :namevar,, ::titlevar; FETCH curs RELATIVE 1 1 INTO :x, :namevar,, ::titlevar; Single row SELECT does not need a FETCH but result is bound to variables: SELECT a,b FROM... INTO :x,:y WHERE HS / DBS05-15-ProgLang 19 12.2.3 ESQL #include <stdio.h< stdio.h> /* declare host variables */ char userid[12] = "ABEL/xyz"; char emp_name[10]; int int emp_number; dept_number; char temp[32]; void sql_error(); /* include the SQL Communications Are */ #include <sqlca.h< sqlca.h> main() { emp_number = 7499; /* handle errors */ EXEC SQL WHENEVER SQLERROR do sql_error("oracle error"); /* connect to Oracle */ EXEC SQL CONNECT :userid; printf("connected.\n"); "); Establish DB /* declare a cursor */ connection EXEC SQL DECLARE emp_cursor CURSOR FOR SELECT ename FROM emp WHERE deptno = :dept_number; HS / DBS05-15-ProgLang 20

ESQL Example: Embedded C printf("department number? "); gets(temp); dept_number = atoi(temp); /* open the cursor and identify the active set */ EXEC SQL OPEN emp_cursor; ; /* fetch and process data in a loop exit when no more data */ EXEC SQL WHENEVER NOT FOUND DO break; while (1) {EXEC SQL FETCH emp_cursor INTO } :emp_name;;.. EXEC SQL CLOSE emp_cursor; EXEC SQL COMMIT WORK RELEASE; exit(0); } Close cursor before another SQL statement is executed HS / DBS05-15-ProgLang 21 ESQL Exception handling Exception handling void sql_error(msg) char *msg* msg; { } char buf[500]; int buflen, msglen; EXEC SQL WHENEVER SQLERROR CONTINUE; EXEC SQL ROLLBACK WORK RELEASE; buflen = sizeof (buf); sqlglm(buf,, &buflen& buflen,, &msglen& msglen); printf("%s\n", ", msg); printf("%*.s ("%*.s\n", msglen, buf); exit(1); HS / DBS05-15-ProgLang 22

ESQL Exception handling EXEC SQL WHENEVER SQLERROR GOTO sql_error;... sql_error: EXEC SQL WHENEVER SQLERROR CONTINUE; EXEC SQL ROLLBACK WORK RELEASE;... Without the WHENEVER SQLERROR CONTINUE statement, a ROLLBACK error would invoke the routine again, starting an infinite loop. HS / DBS05-15-ProgLang 23 12.2.4 Positioned Update Update / Delete statements in general use search predicates to determine the rows to be updated Update M set price_day = price_day+1 where price_day <= 1 Often useful: step through a set of rows and update some of them positioned update DECLARE mycurs FOR SELECT ppd, title FROM M FOR UPDATE ON ppd UPDATE M SET ppd = ppd + 1 WHERE CURRENT OF mycurs /* delete in a /*similar way Caveat: Use the capabilities of SQL! It would be stupid to check a predicate on a row within the FETCH loop and then update the row. A cursor may declared FOR READ ONLY (which basically results in HS / DBS05-15-ProgLang 24 some performance gains)

ESQL Cursor sensitivity Which state has the database during processing? EXEC SQL DECLARE mycurs FOR SELECT price_day, title FROM M FOR UPDATE ON price_day WHERE price_day < 2 EXEC SQL OPEN...... EXEC SQL FETCH mycurs INTO... UPDATE M SET price_day = price_day + 2 WHERE CURRENT OF mycurs /* similar for /* delete Is the row under the cursor still in the result set? Yes and No! A cursor declared INSENSITIVE does not make visible any changes (update, delete) until the cursor is closed and reopened. HS / DBS05-15-ProgLang 25 12.3 Transactions in application programs 12.3.1 Definition Sequence of operations on DB which form a "unit of work" Example: Bank account transfer ("debit / credit') : read (acc1); read (acc2); acc1=acc1-amount ; acc2 = acc2+ amount; write(acc1); write (acc2); System must guarantee "correct execution" "Dependable system" dependable: verlässlich, betriebssicher, zuverlässig HS / DBS05-15-ProgLang 26

Transaction braces. TA Syntax : Every operation on DB between the beginning of the sequence of operations and a COMMIT WORK or ROLLBACK WORK No explicit "transaction begin" command needed... OPEN MyCurs;... ; COMMIT; OPEN... Beginning of first TA (first SQL command in program) end of first TA, beginning of next TA But SQL-3: START TRANSACTION, Postgres: BEGIN HS / DBS05-15-ProgLang 27 Transaction semantics Transactional semantics means: DBS guarantees certain executional properties "All or nothing" semantics ATOMICITY All effects are made permanent at COMMIT, not before. TA has no effect after ROLLBACK "Now and forever" DURABILITY DBS guarantees the effects after COMMIT has been processed successfully "Solve concurrency conflicts" Conflict resolution of concurrent operations on DB ISOLATION "Keep consistent DB consistent" Preservation of integrity CONSISTENCY HS / DBS05-15-ProgLang 28

Transactions How does DB System guarantee the properties? Implementation of DBS Application programming with transaction Syntactically mark unit of work: START TRANSACTION. COMMIT; or: START TRANSACTION. IF (everythingok) COMMIT ELSE ROLLBACK; ENDIF no effect exception handling if application commits but DBS cannot guarantee Isolation levels HS / DBS05-15-ProgLang 29 12.3.2 Isolation Important task of transaction manager: isolate concurrent users from each other SELECT balance INTO :myvar FROM account WHERE acc# = :myacc; If myvar + dispo amount >=0 UPDATE account SET balance = myvar amount WHERE acc# = :myacc; Call ATM_pay_out; ENDIF; COMMIT; SELECT SUM(balance),owner FROM account GROUP BY owner; COMMIT; DBS_OUTPUT.PutLine( ); concurrent execution in independent DB sessions Conflict? Not a big deal in this case, but may be SUM is incorrect. HS / DBS05-15-ProgLang 30

Isolation Worst case: lost update T1: progvar read(x); progvar++; write (x progvar) 1 2 3 4 Concurrent Execution 5 6 T2: progvar read(x); progvar++; write (x progvar) Read of T1 and T2: x=7; Increment by T1: x== 8, increment by t2: x==8 Lost update: two independent updaters update the same object. Conflict may result in a wrong value! Updates is lost! Not allowed in any serious multiuser DBS HS / DBS05-15-ProgLang 31 Isolation levels : control behaviour of transaction No problem at all if only READs How much isolation does a TA need? Application dependent: is it acceptable that the balance per customer does not reflect the correct balances of her account? read / write ratio? What is the conflict probability? Isolation level: The kind of conflicts a program is willing to accept The more isolation the less parallelism HS / DBS05-15-ProgLang 32

Transactions in application programs Isolation Levels Suppose TA1 decreases the prices of some movies in the movie DB by 5% TA2 scrolls through all movies Question: does TA2 "see" the new values before TA1 commits? READ UNCOMMITTED Yes: updates of TA1 are immediately visible but only if TA2 has isolation level read uncommitted SET TRANSACTION READ ONLY, ISOLATION LEVEL READ UNCOMMITTED Lowest locking overhead, but unpleasant effects may happen (Examples?) READ COMMITTED in Postgres HS / DBS05-15-ProgLang 33 Setting isolation levels SET TRANSACTION <mode> [,<mode>] 0 n <mode> = <access mode> [ISOLATION LEVEL] <isolation> DIAGNOSTIC SIZE <simple_value> <access mode > = READ ONLY READ WRITE <isolation> = READ UNCOMMITTED READ COMMITTED REPEATABLE READ SERIALIZABLE Diagnostic: area for details about exceptions, only for ESQL Different default modes: READ UNCOMMITTED READ ONLY else READ WRITE HS / DBS05-15-ProgLang 34

Transactions in application programs READ COMMITTED ("cursor stability") No uncommitted update can be seen by any application But TA might see different states of the same object TA2 : R (a), x=x+a;... TA1 : W(b+10); W(a-10);COMMIT; R(b); x:=x+b;... Value of program variablel x does not reflect DB state because READ is not REPEATABLE Conflicts typically solved by locks ("2-phase locking") If "Read committed" but no "repeatable read" required : read-only transaction need only short read locks higher parallelism HS / DBS05-15-ProgLang 35 Transactions in application programs Isolation levels (4) REPEATABLE READ all read / write conflicts prevented, reads repeatable Lock synchronization: all locks held until end of TA but TA2 : R(a), x=x+a... R(b), x:=x+b,... TA1 : Insert(z); Commit; -- TA2: SUM of attribut of relation S, -- TA1: inserts a row into S Unpleasant effect: Phantom records SERIALIZABLE repeatable read + phantoms avoided HS / DBS05-15-ProgLang 36

Transactions Isolation levels first statement within TA Be careful with default modes SET TRANSACTION READ WRITE; SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED; TA has default access mode of last SET i.e. READ ONLY (!) Read uncommitted dangerous: may cause inconsistencies Read committed is the default in some systems (e.g. Oracle) Serializable important for high frequent short transactions with many potential conflicts. AUTOCOMMIT-mode: implicit COMMIT after each SQL-statement HS / DBS05-15-ProgLang 37 Transaction Rollback / abort ROLLBACK SQL statement like COMMIT "backout" of TA, not any effect on the DB "all-or-nothing semantics" application programmer decides on rollback Abort System kills transaction system failure user session is aborted system recovery transaction rollback caused by internal state (e.g. deadlock) Recovery of TA by system, of application process control flow by programmer. Important: handling of DB exceptions HS / DBS05-15-ProgLang 38

Deadlock abort detection (Embedd( Embedd.. SQL) #define DEADL_ABORT -60 /* ORA specific #define TRUE 1 EXEC SQL sql WHENEVER sqlerror CONTINUE; int count = 0; while (TRUE) { EXEC SQL UPDATE customers set discnt = 1.1*discnt WHERE city ='Berlin'; if (sqlca.sqlcode == DEAD_ABORT) { count++; if (count < 4) { exec sql ROLLBACK; } else break; else if (sqlca.sqlcode <0) break; }if (sqlca.sqlcode < 0) { print_dberror(); exec sql rollback; /* application: go back to start of this return -1 /* transaction HS / DBS05-15-ProgLang 39 } return 0; SAVEPOINTS Rollback can be expensive in long TAs Use SAVEPOINTs to limit work to be redone operations on DB more operations on DB TA begin SAVEPOINT s UNDO everything after s commit 'safe' operations HS / DBS05-15-ProgLang 40

Transaction in applications Never have user interaction within a TA Resources will be blocked for long time bad! EXEC SQL SELECT price, quantity into :price, :qoh... while (TRUE){ printf("we have %d units... of %d each \n", qoh, price) printf ("How many... ",...) } if (qoh >= numberordered){ /* check correct input /* and exit loop EXEC SQL UPDATE products set quantity =... } else... Bad design: resource blocking EXEC SQL COMMITT; time depends on user How does a better program design look like? HS / DBS05-15-ProgLang 41