Develop and Download Open Source Software

Browse CVS Repository

Contents of /xoonips/AL/criteria.cc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (show annotations) (download) (as text)
Wed Nov 24 06:54:31 2004 UTC (19 years, 4 months ago) by youi
Branch: MAIN
File MIME type: text/x-c++src
initial version

1 /*
2 * SQL実行結果の範囲指定,並べ替え条件を管理するcriteriaクラスの定義
3 *
4 * $Revision$
5 * $Log$
6 *
7 */
8 #include <stdlib.h>
9 #include <string.h>
10
11 #include "common.h"
12 #include "criteria.h"
13
14 /**
15 * SQLのORDERBYの設定を記憶するクラス
16 *
17 * @param column カラム名
18 * @param order 昇順,降順の指定(未指定時 orderby::ASC)
19 * @ref orderby::ASC
20 * @ref orderby::DESC
21 *
22 */
23 orderby::orderby( const char* column = "", int order = orderby::ASC ){
24 setValue( &this -> column, column );
25 this -> order = order;
26 this -> next = 0;
27 }
28
29 /**
30 *
31 * デストラクタ
32 *
33 * カラム名のメモリ領域を開放する
34 *
35 */
36 orderby::~orderby( ){
37 delete this -> column;
38 }
39
40 /**
41 *
42 * カラム名を返す
43 * @return カラム名
44 *
45 */
46 const char* orderby::getColumn( ) const { return column; }
47
48 /**
49 *
50 * 昇順,または降順を返す
51 * @return 昇順,または降順
52 * @ref orderby::ASC
53 * @ref orderby::DESC
54 *
55 */
56 order_t orderby::getOrder( ) const{ return order; }
57
58 /**
59 *
60 * SQLの範囲指定(LIMIT)や,ソート順(カラム名と昇順降順)を管理するクラ
61 * ス.
62 *
63 */
64 criteria::criteria( )
65 {
66 start = 0;
67 rows = 0;
68 indexOfOrders = 0;
69 ordersLen = 0;
70 ordersMax = 16;
71 orders = new orderby*[ ordersMax ];
72 memset( orders, 0, sizeof( orderby* ) * ordersMax );
73 }
74
75 /**
76 *
77 * デストラクタ
78 *
79 * addOrderByで追加したorderbyインスタンスの解放を行なう
80 *
81 * @ref addOrderBy
82 *
83 */
84 criteria::~criteria( )
85 {
86 if( orders != 0 ){
87 for( int i = 0; i < ordersLen; i++ ) delete orders[ i ];
88 delete[] orders;
89 }
90 }
91
92 /**
93 *
94 * SQL実行結果として出力する範囲を,開始行と行数で指定する.
95 *
96 * @param start 開始行
97 * @param rows 行数
98 *
99 */
100 void criteria::setLimit( int start , int rows )
101 {
102 this -> start = start;
103 this -> rows = rows;
104 }
105
106 /**
107 *
108 * 昇順降順の条件を追加する.SQL実行時は最初に追加したものを最初のソー
109 * ト条件とする.
110 *
111 * @param order orderbyのアドレス
112 *
113 */
114 void criteria::addOrderBy( orderby *order )
115 {
116 if( ordersMax == ordersLen ){
117 //ordersのいっぱいまでデータがあるので,拡張する
118 orderby** ptr = new orderby*[ ordersMax * 2 ];
119 memset( ptr, 0, sizeof( orderby* ) * ordersMax * 2 );
120 memcpy( ptr, orders, sizeof( orderby* ) * ordersMax );
121 delete[] orders;
122 ordersMax *= 2;
123 orders = ptr;
124 }
125 orders[ ordersLen ] = order;
126 ordersLen++;
127 }
128
129 /**
130 *
131 * 最初のorderbyを取り出す. 2番目以降のorderbyはnextOrderByで取り出す.<br>
132 * ※この関数はスレッドに対して非安全(unsafe)です
133 *
134 * @return 最初のorderby
135 * @return 0 これ以上のorderbyはない
136 * @ref nextOrderBy
137 *
138 */
139 const orderby* criteria::headOrderBy( )
140 {
141 indexOfOrders = 0;
142 if( indexOfOrders >= ordersLen ) return 0;
143 return orders[ indexOfOrders++ ];
144 }
145
146 /**
147 *
148 * orderbyを取り出す.<br>
149 * ※この関数はスレッドに対して非安全(unsafe)です
150 *
151 * @return orderbyのインスタンス
152 * @return 0 これ以上のorderbyはない
153 * @ref headNextOrderBy
154 *
155 */
156 const orderby* criteria::nextOrderBy( )
157 {
158 if( indexOfOrders >= ordersLen ) return 0;
159 return orders[ indexOfOrders++ ];
160 }
161
162 /**
163 *
164 * LIMIT設定,全てのORDERBY設定を削除します.
165 *
166 */
167 void criteria::clearAll( )
168 {
169 memset( orders, 0, sizeof( orderby* ) * ordersMax );
170 ordersLen = 0;
171 start = rows = 0;
172 }
173
174 /**
175 *
176 * LIMITの開始行
177 *
178 * @return
179 *
180 */
181 int criteria::getLimitStart( ) const { return start; }
182
183 /**
184 *
185 * LIMITの行数
186 *
187 * @return
188 *
189 */
190 int criteria::getLimitRows( ) const{ return rows; }

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26