1"=====================================================================
2|
3|   Generic database interface - Table class (bridge with ROE)
4|
5|
6 ======================================================================"
7
8"======================================================================
9|
10| Copyright 2008 Free Software Foundation, Inc.
11| Written by Paolo Bonzini
12|
13| This file is part of the GNU Smalltalk class library.
14|
15| The GNU Smalltalk class library is free software; you can redistribute it
16| and/or modify it under the terms of the GNU Lesser General Public License
17| as published by the Free Software Foundation; either version 2.1, or (at
18| your option) any later version.
19|
20| The GNU Smalltalk class library is distributed in the hope that it will be
21| useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
22| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser
23| General Public License for more details.
24|
25| You should have received a copy of the GNU Lesser General Public License
26| along with the GNU Smalltalk class library; see the file COPYING.LIB.
27| If not, write to the Free Software Foundation, 59 Temple Place - Suite
28| 330, Boston, MA 02110-1301, USA.
29|
30 ======================================================================
31"
32
33
34
35ROE.RASQLRelation subclass: Table [
36
37    <category: 'DBI'>
38    <comment: nil>
39
40    | columns |
41
42    basicExec: aString [
43	<category: 'private'>
44	^connection do: aString
45    ]
46
47    basicQuery: aString [
48	<category: 'private'>
49	^(connection select: aString) contents
50    ]
51
52    columnsArray [
53	"Answer a Dictionary of column name -> ColumnInfo pairs (abstract)."
54	self subclassResponsibility
55    ]
56
57    columns [
58        <category: 'accessing'>
59        columns isNil
60            ifTrue:
61                [| n array |
62		array := self columnsArray.
63                columns := LookupTable new: array size.
64                array do: [:col | columns at: col name put: col]].
65        ^columns
66    ]
67
68    columnNames [
69	"Answer an array of column names in order (abstract)."
70
71	<category: 'accessing'>
72	^self columnsArray collect: [:each | self name]
73    ]
74
75    columnAt: aIndex [
76        "Answer the aIndex'th column name."
77
78        <category: 'accessing'>
79        ^(self columnsArray at: aIndex) name
80    ]
81
82    database [
83	"Returns the database name for this table.  This corresponds
84	 to the catalog in SQL standard parlance."
85
86	<category: 'accessing'>
87	^self connection database
88    ]
89
90    discoverAttributes [
91	<category: 'private'>
92	^self columnsArray
93	    collect: [:each | RASimpleAttribute named: each name relation: self]
94    ]
95
96    size [
97	<category: 'core'>
98	^(self query: self sqlCount) first atIndex: 1
99    ]
100
101    print: anObject on: aStream [
102        <category: 'printing'>
103        self connection fieldConverter print: anObject on: aStream
104    ]
105]
106