
1 // 2 // Copyright (c) 2007, John Sublett 3 // Licensed under the Academic Free License version 3.0 4 // 5 // History: 6 // 21 Dec 07 John Sublett Creation 7 // 8 9 ** 10 ** Statement manages a statement prepared for a database 11 ** connection. 12 ** 13 ** Refer to the [Sql docs]`docLib::Sql` for more details. 14 ** 15 class Statement 16 { 17 ** 18 ** Make a new statement with the specified SQL text. 19 ** 20 internal new make(Connection conn, Str sql) 21 { 22 this.conn = conn 23 this.sql = sql 24 } 25 26 ** 27 ** Prepare this statement for use with the specified 28 ** connection. 29 ** 30 internal native Statement prepare() 31 32 ** 33 ** Execute the statement and get a relational table as the result. 34 ** If 'of' is 'null', the result is returned as a 'List' 35 ** of 'Rows'. The 'Cols' are available from 'List.of.fields' or 36 ** on 'type.fields' of each row instance. If 'of' is specified, 37 ** then the result is returned as a 'List' of that type. Columns 38 ** are mapped to the type's fields. If a column cannot be mapped 39 ** to a field, then an 'SqlErr' is thrown. 40 ** 41 native Obj[] query(Str:Obj params, Type of := null) 42 43 native Void queryEach(Str:Obj params, Type of, |Obj row| eachFunc) 44 45 ** 46 ** Execute a SQL statement and if applicable return 47 ** the number of rows modified. 48 ** 49 native Int execute(Str:Obj params) 50 51 ** 52 ** Close the statement. 53 ** 54 native Void close() 55 56 /////////////////////////////////////////////////////////// 57 // Fields 58 /////////////////////////////////////////////////////////// 59 60 ** 61 ** The connection that this statement uses. 62 ** 63 readonly Connection conn 64 65 ** 66 ** The SQL text used to create this statement. 67 ** 68 readonly Str sql 69 }