Merge lp:~olafvdspek/drizzle/rf1 into lp:drizzle

Proposed by Olaf van der Spek
Status: Needs review
Proposed branch: lp:~olafvdspek/drizzle/rf1
Merge into: lp:drizzle
Diff against target: 397 lines (+49/-150)
3 files modified
drizzled/error/sql_state.cc (+4/-9)
drizzled/error/sql_state.h (+3/-5)
drizzled/table/instance/base.cc (+42/-136)
To merge this branch: bzr merge lp:~olafvdspek/drizzle/rf1
Reviewer Review Type Date Requested Status
Drizzle Trunk Pending
Review via email: mp+118245@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Brian Aker (brianaker) wrote :

Style-wise, we use {} in all cases. This patch removes that in a few cases.

This is for readability.

Revision history for this message
Olaf van der Spek (olafvdspek) wrote :

Do we? Coding standards doesn't mention it. It even contains a few examples that don't.

Revision history for this message
Brian Aker (brianaker) wrote :

This is something that Trond slipped up on at one point. I thought we had updated the style guide for this.

Revision history for this message
Olaf van der Spek (olafvdspek) wrote :

Where did I remove the braces?

Revision history for this message
Olaf van der Spek (olafvdspek) wrote :

Ah, I found one if statement. Do you want me to update the patch?

--
Olaf

Unmerged revisions

2579. By Olaf van der Spek

Refactor

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'drizzled/error/sql_state.cc'
2--- drizzled/error/sql_state.cc 2011-02-17 00:14:13 +0000
3+++ drizzled/error/sql_state.cc 2012-08-04 14:50:32 +0000
4@@ -28,15 +28,12 @@
5
6 using namespace std;
7
8-namespace drizzled
9-{
10-
11-namespace error
12-{
13+namespace drizzled {
14+namespace error {
15
16 struct sql_state_t
17 {
18- drizzled::error_t drizzle_errno;
19+ error_t drizzle_errno;
20 const char *odbc_state;
21 const char *jdbc_state;
22 };
23@@ -171,15 +168,13 @@
24 { ER_DUP_ENTRY_WITH_KEY_NAME ,"23000", "S1009" },
25 };
26
27-static bool compare_errno_map(sql_state_t a,
28- sql_state_t b)
29+static bool compare_errno_map(sql_state_t a, sql_state_t b)
30 {
31 return (a.drizzle_errno < b.drizzle_errno);
32 }
33
34 const char *convert_to_sqlstate(drizzled::error_t drizzle_errno)
35 {
36-
37 sql_state_t drizzle_err_state= {drizzle_errno, NULL, NULL};
38 sql_state_t* result=
39 lower_bound(&sqlstate_map[0],
40
41=== modified file 'drizzled/error/sql_state.h'
42--- drizzled/error/sql_state.h 2011-03-14 05:40:28 +0000
43+++ drizzled/error/sql_state.h 2012-08-04 14:50:32 +0000
44@@ -19,12 +19,10 @@
45
46 #pragma once
47
48-namespace drizzled
49-{
50-namespace error
51-{
52+namespace drizzled {
53+namespace error {
54
55-const char *convert_to_sqlstate(drizzled::error_t drizzle_errno);
56+const char* convert_to_sqlstate(error_t);
57
58 } /* namespace error */
59 } /* namespace drizzled */
60
61=== modified file 'drizzled/table/instance/base.cc'
62--- drizzled/table/instance/base.cc 2012-07-11 14:06:00 +0000
63+++ drizzled/table/instance/base.cc 2012-08-04 14:50:32 +0000
64@@ -34,7 +34,6 @@
65 #include <sys/stat.h>
66 #include <fcntl.h>
67
68-
69 #include <cassert>
70
71 #include <drizzled/error.h>
72@@ -147,7 +146,7 @@
73 abort();
74 }
75
76-static Item* default_value_item(enum_field_types field_type, const charset_info_st& charset, bool default_null,
77+static Item* default_value_item(enum_field_types field_type, const charset_info_st& charset, bool default_null,
78 const string& default_value, const string& default_bin_value)
79 {
80 if (default_null)
81@@ -498,7 +497,7 @@
82 normalized_path= str_ref(new_path);
83 }
84
85-TableShare::~TableShare()
86+TableShare::~TableShare()
87 {
88 storage_engine= NULL;
89 delete table_identifier;
90@@ -676,15 +675,11 @@
91 if (table.field(part.fieldnr()).type() == message::Table::Field::VARCHAR
92 || table.field(part.fieldnr()).type() == message::Table::Field::BLOB)
93 {
94- uint32_t collation_id;
95-
96- if (table.field(part.fieldnr()).string_options().has_collation_id())
97- collation_id= table.field(part.fieldnr()).string_options().collation_id();
98- else
99- collation_id= table.options().collation_id();
100+ uint32_t collation_id= table.field(part.fieldnr()).string_options().has_collation_id()
101+ ? table.field(part.fieldnr()).string_options().collation_id()
102+ : table.options().collation_id();
103
104 const charset_info_st *cs= get_charset(collation_id);
105-
106 mbmaxlen= cs->mbmaxlen;
107 }
108 key_part->length*= mbmaxlen;
109@@ -872,7 +867,7 @@
110 {
111 t->type_names[n]= mem().strdup(field_options.field_value(n));
112
113- /*
114+ /*
115 * Go ask the charset what the length is as for "" length=1
116 * and there's stripping spaces or some other crack going on.
117 */
118@@ -911,7 +906,7 @@
119 {
120 unireg_type= Field::TIMESTAMP_DNUN_FIELD;
121 }
122- else if (! pfield.options().has_update_expression())
123+ else if (not pfield.options().has_update_expression())
124 {
125 unireg_type= Field::TIMESTAMP_DN_FIELD;
126 }
127@@ -1010,10 +1005,9 @@
128 {
129 message::Table::Field::StringFieldOptions field_options= pfield.string_options();
130
131- charset= get_charset(field_options.has_collation_id() ?
132- field_options.collation_id() : 0);
133+ charset= get_charset(field_options.has_collation_id() ? field_options.collation_id() : 0);
134
135- if (! charset)
136+ if (not charset)
137 charset= default_charset_info;
138
139 field_length= field_options.length() * charset->mbmaxlen;
140@@ -1043,8 +1037,7 @@
141 {
142 message::Table::Field::NumericFieldOptions fo= pfield.numeric_options();
143
144- field_length= class_decimal_precision_to_length(fo.precision(), fo.scale(),
145- false);
146+ field_length= class_decimal_precision_to_length(fo.precision(), fo.scale(), false);
147 break;
148 }
149 case DRIZZLE_TYPE_DATETIME:
150@@ -1106,16 +1099,7 @@
151 abort(); // Programming error
152 }
153
154- bool is_not_null= false;
155-
156- if (not pfield.constraints().is_nullable())
157- {
158- is_not_null= true;
159- }
160- else if (pfield.constraints().is_notnull())
161- {
162- is_not_null= true;
163- }
164+ bool is_not_null= not pfield.constraints().is_nullable() || pfield.constraints().is_notnull();
165
166 Field* f= make_field(pfield,
167 record + field_offsets[fieldnr] + data_offset,
168@@ -1212,8 +1196,7 @@
169
170 if (use_hash) /* supposedly this never fails... but comments lie */
171 {
172- const char *local_field_name= _fields[fieldnr]->field_name;
173- name_hash.insert(make_pair(local_field_name, &(_fields[fieldnr])));
174+ name_hash.insert(make_pair(_fields[fieldnr]->field_name, &(_fields[fieldnr])));
175 }
176 }
177
178@@ -1226,7 +1209,7 @@
179 partnr < keyinfo->key_parts;
180 partnr++, key_part++)
181 {
182- /*
183+ /*
184 * Fix up key_part->offset by adding data_offset.
185 * We really should compute offset as well.
186 * But at least this way we are a little better.
187@@ -1359,8 +1342,7 @@
188 set_if_bigger(max_unique_length,keyinfo->key_length);
189 }
190 }
191- if (local_primary_key < MAX_KEY &&
192- (keys_in_use.test(local_primary_key)))
193+ if (local_primary_key < MAX_KEY && keys_in_use.test(local_primary_key))
194 {
195 primary_key= local_primary_key;
196 /*
197@@ -1373,8 +1355,7 @@
198 if (local_field && local_field->result_type() == INT_RESULT)
199 {
200 /* note that fieldnr here (and rowid_field_offset) starts from 1 */
201- rowid_field_offset= (key_info[local_primary_key].key_part[0].
202- fieldnr);
203+ rowid_field_offset= (key_info[local_primary_key].key_part[0].fieldnr);
204 }
205 }
206 }
207@@ -1597,8 +1578,7 @@
208 *field_ptr= 0; // End marker
209
210 if (found_next_number_field)
211- outparam.found_next_number_field=
212- outparam.getField(positionFields(found_next_number_field));
213+ outparam.found_next_number_field= outparam.getField(positionFields(found_next_number_field));
214 if (timestamp_field)
215 outparam.timestamp_field= (field::Epoch*) outparam.getField(timestamp_field->position());
216
217@@ -1655,11 +1635,9 @@
218 if (db_stat)
219 {
220 assert(!(db_stat & HA_WAIT_IF_LOCKED));
221- int ha_err;
222-
223- if ((ha_err= (outparam.cursor->ha_open(identifier,
224- (db_stat & HA_READ_ONLY ? O_RDONLY : O_RDWR),
225- (db_stat & HA_OPEN_TEMPORARY ? HA_OPEN_TMP_TABLE : HA_OPEN_IGNORE_IF_LOCKED) | ha_open_flags))))
226+ if (int ha_err= (outparam.cursor->ha_open(identifier,
227+ (db_stat & HA_READ_ONLY ? O_RDONLY : O_RDWR),
228+ (db_stat & HA_OPEN_TEMPORARY ? HA_OPEN_TMP_TABLE : HA_OPEN_IGNORE_IF_LOCKED) | ha_open_flags)))
229 {
230 switch (ha_err)
231 {
232@@ -1699,7 +1677,8 @@
233 char buff[FN_REFLEN];
234 myf errortype= ME_ERROR+ME_WAITTANG;
235
236- switch (pass_error) {
237+ switch (pass_error)
238+ {
239 case 7:
240 case 1:
241 if (db_errno == ENOENT)
242@@ -1722,7 +1701,7 @@
243 {
244 const char *csname= get_charset_name((uint32_t) pass_errarg);
245 char tmp[10];
246- if (!csname || csname[0] =='?')
247+ if (not csname || csname[0] =='?')
248 {
249 snprintf(tmp, sizeof(tmp), "#%d", pass_errarg);
250 csname= tmp;
251@@ -1784,120 +1763,48 @@
252 const charset_info_st * field_charset,
253 Field::utype unireg_check,
254 TYPELIB *interval,
255- const char *field_name,
256+ const char *field_name,
257 bool is_unsigned)
258 {
259- if (! is_nullable)
260+ if (is_nullable)
261+ {
262+ null_bit= ((unsigned char) 1) << null_bit;
263+ }
264+ else
265 {
266 null_pos=0;
267 null_bit=0;
268 }
269- else
270- {
271- null_bit= ((unsigned char) 1) << null_bit;
272- }
273
274 switch (field_type)
275 {
276 case DRIZZLE_TYPE_ENUM:
277- return new (&mem_root) Field_enum(ptr,
278- field_length,
279- null_pos,
280- null_bit,
281- field_name,
282- interval,
283- field_charset);
284+ return new (&mem_root) Field_enum(ptr, field_length, null_pos, null_bit, field_name, interval, field_charset);
285 case DRIZZLE_TYPE_VARCHAR:
286 setVariableWidth();
287- return new (&mem_root) Field_varstring(ptr,field_length,
288- ha_varchar_packlength(field_length),
289- null_pos,null_bit,
290- field_name,
291- field_charset);
292+ return new (&mem_root) Field_varstring(ptr,field_length, ha_varchar_packlength(field_length), null_pos,null_bit, field_name, field_charset);
293 case DRIZZLE_TYPE_BLOB:
294- return new (&mem_root) Field_blob(ptr,
295- null_pos,
296- null_bit,
297- field_name,
298- this,
299- field_charset);
300+ return new (&mem_root) Field_blob(ptr, null_pos, null_bit, field_name, this, field_charset);
301 case DRIZZLE_TYPE_DECIMAL:
302- return new (&mem_root) Field_decimal(ptr,
303- field_length,
304- null_pos,
305- null_bit,
306- unireg_check,
307- field_name,
308- decimals);
309+ return new (&mem_root) Field_decimal(ptr, field_length, null_pos, null_bit, unireg_check, field_name, decimals);
310 case DRIZZLE_TYPE_DOUBLE:
311- return new (&mem_root) Field_double(ptr,
312- field_length,
313- null_pos,
314- null_bit,
315- unireg_check,
316- field_name,
317- decimals,
318- false,
319- false /* is_unsigned */);
320+ return new (&mem_root) Field_double(ptr, field_length, null_pos, null_bit, unireg_check, field_name, decimals, false, false /* is_unsigned */);
321 case DRIZZLE_TYPE_UUID:
322- return new (&mem_root) field::Uuid(ptr,
323- field_length,
324- null_pos,
325- null_bit,
326- field_name);
327+ return new (&mem_root) field::Uuid(ptr, field_length, null_pos, null_bit, field_name);
328 case DRIZZLE_TYPE_IPV6:
329- return new (&mem_root) field::IPv6(ptr,
330- field_length,
331- null_pos,
332- null_bit,
333- field_name);
334+ return new (&mem_root) field::IPv6(ptr, field_length, null_pos, null_bit, field_name);
335 case DRIZZLE_TYPE_BOOLEAN:
336- return new (&mem_root) field::Boolean(ptr,
337- field_length,
338- null_pos,
339- null_bit,
340- field_name,
341- is_unsigned);
342+ return new (&mem_root) field::Boolean(ptr, field_length, null_pos, null_bit, field_name, is_unsigned);
343 case DRIZZLE_TYPE_LONG:
344- return new (&mem_root) field::Int32(ptr,
345- field_length,
346- null_pos,
347- null_bit,
348- unireg_check,
349- field_name);
350+ return new (&mem_root) field::Int32(ptr, field_length, null_pos, null_bit, unireg_check, field_name);
351 case DRIZZLE_TYPE_LONGLONG:
352- {
353- if (is_unsigned)
354- {
355- return new (&mem_root) field::Size(ptr,
356- field_length,
357- null_pos,
358- null_bit,
359- unireg_check,
360- field_name);
361- }
362-
363- return new (&mem_root) field::Int64(ptr,
364- field_length,
365- null_pos,
366- null_bit,
367- unireg_check,
368- field_name);
369- }
370+ if (is_unsigned)
371+ return new (&mem_root) field::Size(ptr, field_length, null_pos, null_bit, unireg_check, field_name);
372+ return new (&mem_root) field::Int64(ptr, field_length, null_pos, null_bit, unireg_check, field_name);
373 case DRIZZLE_TYPE_MICROTIME:
374- return new (&mem_root) field::Microtime(ptr,
375- null_pos,
376- null_bit,
377- unireg_check,
378- field_name,
379- this);
380+ return new (&mem_root) field::Microtime(ptr, null_pos, null_bit, unireg_check, field_name, this);
381 case DRIZZLE_TYPE_TIMESTAMP:
382- return new (&mem_root) field::Epoch(ptr,
383- null_pos,
384- null_bit,
385- unireg_check,
386- field_name,
387- this);
388+ return new (&mem_root) field::Epoch(ptr, null_pos, null_bit, unireg_check, field_name, this);
389 case DRIZZLE_TYPE_TIME:
390 return new (&mem_root) field::Time(ptr, field_length, null_pos, null_bit, field_name);
391 case DRIZZLE_TYPE_DATE:
392@@ -1916,5 +1823,4 @@
393 version= g_refresh_version;
394 }
395
396-
397 } /* namespace drizzled */

Subscribers

People subscribed via source and target branches