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
=== modified file 'drizzled/error/sql_state.cc'
--- drizzled/error/sql_state.cc 2011-02-17 00:14:13 +0000
+++ drizzled/error/sql_state.cc 2012-08-04 14:50:32 +0000
@@ -28,15 +28,12 @@
2828
29using namespace std;29using namespace std;
3030
31namespace drizzled31namespace drizzled {
32{32namespace error {
33
34namespace error
35{
3633
37struct sql_state_t34struct sql_state_t
38{35{
39 drizzled::error_t drizzle_errno;36 error_t drizzle_errno;
40 const char *odbc_state;37 const char *odbc_state;
41 const char *jdbc_state;38 const char *jdbc_state;
42};39};
@@ -171,15 +168,13 @@
171 { ER_DUP_ENTRY_WITH_KEY_NAME ,"23000", "S1009" },168 { ER_DUP_ENTRY_WITH_KEY_NAME ,"23000", "S1009" },
172};169};
173170
174static bool compare_errno_map(sql_state_t a,171static bool compare_errno_map(sql_state_t a, sql_state_t b)
175 sql_state_t b)
176{172{
177 return (a.drizzle_errno < b.drizzle_errno);173 return (a.drizzle_errno < b.drizzle_errno);
178}174}
179175
180const char *convert_to_sqlstate(drizzled::error_t drizzle_errno)176const char *convert_to_sqlstate(drizzled::error_t drizzle_errno)
181{177{
182
183 sql_state_t drizzle_err_state= {drizzle_errno, NULL, NULL};178 sql_state_t drizzle_err_state= {drizzle_errno, NULL, NULL};
184 sql_state_t* result=179 sql_state_t* result=
185 lower_bound(&sqlstate_map[0],180 lower_bound(&sqlstate_map[0],
186181
=== modified file 'drizzled/error/sql_state.h'
--- drizzled/error/sql_state.h 2011-03-14 05:40:28 +0000
+++ drizzled/error/sql_state.h 2012-08-04 14:50:32 +0000
@@ -19,12 +19,10 @@
1919
20#pragma once20#pragma once
2121
22namespace drizzled22namespace drizzled {
23{23namespace error {
24namespace error
25{
2624
27const char *convert_to_sqlstate(drizzled::error_t drizzle_errno);25const char* convert_to_sqlstate(error_t);
2826
29} /* namespace error */27} /* namespace error */
30} /* namespace drizzled */28} /* namespace drizzled */
3129
=== modified file 'drizzled/table/instance/base.cc'
--- drizzled/table/instance/base.cc 2012-07-11 14:06:00 +0000
+++ drizzled/table/instance/base.cc 2012-08-04 14:50:32 +0000
@@ -34,7 +34,6 @@
34#include <sys/stat.h>34#include <sys/stat.h>
35#include <fcntl.h>35#include <fcntl.h>
3636
37
38#include <cassert>37#include <cassert>
3938
40#include <drizzled/error.h>39#include <drizzled/error.h>
@@ -147,7 +146,7 @@
147 abort();146 abort();
148}147}
149148
150static Item* default_value_item(enum_field_types field_type, const charset_info_st& charset, bool default_null, 149static Item* default_value_item(enum_field_types field_type, const charset_info_st& charset, bool default_null,
151 const string& default_value, const string& default_bin_value)150 const string& default_value, const string& default_bin_value)
152{151{
153 if (default_null)152 if (default_null)
@@ -498,7 +497,7 @@
498 normalized_path= str_ref(new_path);497 normalized_path= str_ref(new_path);
499}498}
500499
501TableShare::~TableShare() 500TableShare::~TableShare()
502{501{
503 storage_engine= NULL;502 storage_engine= NULL;
504 delete table_identifier;503 delete table_identifier;
@@ -676,15 +675,11 @@
676 if (table.field(part.fieldnr()).type() == message::Table::Field::VARCHAR675 if (table.field(part.fieldnr()).type() == message::Table::Field::VARCHAR
677 || table.field(part.fieldnr()).type() == message::Table::Field::BLOB)676 || table.field(part.fieldnr()).type() == message::Table::Field::BLOB)
678 {677 {
679 uint32_t collation_id;678 uint32_t collation_id= table.field(part.fieldnr()).string_options().has_collation_id()
680679 ? table.field(part.fieldnr()).string_options().collation_id()
681 if (table.field(part.fieldnr()).string_options().has_collation_id())680 : table.options().collation_id();
682 collation_id= table.field(part.fieldnr()).string_options().collation_id();
683 else
684 collation_id= table.options().collation_id();
685681
686 const charset_info_st *cs= get_charset(collation_id);682 const charset_info_st *cs= get_charset(collation_id);
687
688 mbmaxlen= cs->mbmaxlen;683 mbmaxlen= cs->mbmaxlen;
689 }684 }
690 key_part->length*= mbmaxlen;685 key_part->length*= mbmaxlen;
@@ -872,7 +867,7 @@
872 {867 {
873 t->type_names[n]= mem().strdup(field_options.field_value(n));868 t->type_names[n]= mem().strdup(field_options.field_value(n));
874869
875 /* 870 /*
876 * Go ask the charset what the length is as for "" length=1871 * Go ask the charset what the length is as for "" length=1
877 * and there's stripping spaces or some other crack going on.872 * and there's stripping spaces or some other crack going on.
878 */873 */
@@ -911,7 +906,7 @@
911 {906 {
912 unireg_type= Field::TIMESTAMP_DNUN_FIELD;907 unireg_type= Field::TIMESTAMP_DNUN_FIELD;
913 }908 }
914 else if (! pfield.options().has_update_expression())909 else if (not pfield.options().has_update_expression())
915 {910 {
916 unireg_type= Field::TIMESTAMP_DN_FIELD;911 unireg_type= Field::TIMESTAMP_DN_FIELD;
917 }912 }
@@ -1010,10 +1005,9 @@
1010 {1005 {
1011 message::Table::Field::StringFieldOptions field_options= pfield.string_options();1006 message::Table::Field::StringFieldOptions field_options= pfield.string_options();
10121007
1013 charset= get_charset(field_options.has_collation_id() ?1008 charset= get_charset(field_options.has_collation_id() ? field_options.collation_id() : 0);
1014 field_options.collation_id() : 0);
10151009
1016 if (! charset)1010 if (not charset)
1017 charset= default_charset_info;1011 charset= default_charset_info;
10181012
1019 field_length= field_options.length() * charset->mbmaxlen;1013 field_length= field_options.length() * charset->mbmaxlen;
@@ -1043,8 +1037,7 @@
1043 {1037 {
1044 message::Table::Field::NumericFieldOptions fo= pfield.numeric_options();1038 message::Table::Field::NumericFieldOptions fo= pfield.numeric_options();
10451039
1046 field_length= class_decimal_precision_to_length(fo.precision(), fo.scale(),1040 field_length= class_decimal_precision_to_length(fo.precision(), fo.scale(), false);
1047 false);
1048 break;1041 break;
1049 }1042 }
1050 case DRIZZLE_TYPE_DATETIME:1043 case DRIZZLE_TYPE_DATETIME:
@@ -1106,16 +1099,7 @@
1106 abort(); // Programming error1099 abort(); // Programming error
1107 }1100 }
11081101
1109 bool is_not_null= false;1102 bool is_not_null= not pfield.constraints().is_nullable() || pfield.constraints().is_notnull();
1110
1111 if (not pfield.constraints().is_nullable())
1112 {
1113 is_not_null= true;
1114 }
1115 else if (pfield.constraints().is_notnull())
1116 {
1117 is_not_null= true;
1118 }
11191103
1120 Field* f= make_field(pfield,1104 Field* f= make_field(pfield,
1121 record + field_offsets[fieldnr] + data_offset,1105 record + field_offsets[fieldnr] + data_offset,
@@ -1212,8 +1196,7 @@
12121196
1213 if (use_hash) /* supposedly this never fails... but comments lie */1197 if (use_hash) /* supposedly this never fails... but comments lie */
1214 {1198 {
1215 const char *local_field_name= _fields[fieldnr]->field_name;1199 name_hash.insert(make_pair(_fields[fieldnr]->field_name, &(_fields[fieldnr])));
1216 name_hash.insert(make_pair(local_field_name, &(_fields[fieldnr])));
1217 }1200 }
1218 }1201 }
12191202
@@ -1226,7 +1209,7 @@
1226 partnr < keyinfo->key_parts;1209 partnr < keyinfo->key_parts;
1227 partnr++, key_part++)1210 partnr++, key_part++)
1228 {1211 {
1229 /* 1212 /*
1230 * Fix up key_part->offset by adding data_offset.1213 * Fix up key_part->offset by adding data_offset.
1231 * We really should compute offset as well.1214 * We really should compute offset as well.
1232 * But at least this way we are a little better.1215 * But at least this way we are a little better.
@@ -1359,8 +1342,7 @@
1359 set_if_bigger(max_unique_length,keyinfo->key_length);1342 set_if_bigger(max_unique_length,keyinfo->key_length);
1360 }1343 }
1361 }1344 }
1362 if (local_primary_key < MAX_KEY &&1345 if (local_primary_key < MAX_KEY && keys_in_use.test(local_primary_key))
1363 (keys_in_use.test(local_primary_key)))
1364 {1346 {
1365 primary_key= local_primary_key;1347 primary_key= local_primary_key;
1366 /*1348 /*
@@ -1373,8 +1355,7 @@
1373 if (local_field && local_field->result_type() == INT_RESULT)1355 if (local_field && local_field->result_type() == INT_RESULT)
1374 {1356 {
1375 /* note that fieldnr here (and rowid_field_offset) starts from 1 */1357 /* note that fieldnr here (and rowid_field_offset) starts from 1 */
1376 rowid_field_offset= (key_info[local_primary_key].key_part[0].1358 rowid_field_offset= (key_info[local_primary_key].key_part[0].fieldnr);
1377 fieldnr);
1378 }1359 }
1379 }1360 }
1380 }1361 }
@@ -1597,8 +1578,7 @@
1597 *field_ptr= 0; // End marker1578 *field_ptr= 0; // End marker
15981579
1599 if (found_next_number_field)1580 if (found_next_number_field)
1600 outparam.found_next_number_field=1581 outparam.found_next_number_field= outparam.getField(positionFields(found_next_number_field));
1601 outparam.getField(positionFields(found_next_number_field));
1602 if (timestamp_field)1582 if (timestamp_field)
1603 outparam.timestamp_field= (field::Epoch*) outparam.getField(timestamp_field->position());1583 outparam.timestamp_field= (field::Epoch*) outparam.getField(timestamp_field->position());
16041584
@@ -1655,11 +1635,9 @@
1655 if (db_stat)1635 if (db_stat)
1656 {1636 {
1657 assert(!(db_stat & HA_WAIT_IF_LOCKED));1637 assert(!(db_stat & HA_WAIT_IF_LOCKED));
1658 int ha_err;1638 if (int ha_err= (outparam.cursor->ha_open(identifier,
16591639 (db_stat & HA_READ_ONLY ? O_RDONLY : O_RDWR),
1660 if ((ha_err= (outparam.cursor->ha_open(identifier,1640 (db_stat & HA_OPEN_TEMPORARY ? HA_OPEN_TMP_TABLE : HA_OPEN_IGNORE_IF_LOCKED) | ha_open_flags)))
1661 (db_stat & HA_READ_ONLY ? O_RDONLY : O_RDWR),
1662 (db_stat & HA_OPEN_TEMPORARY ? HA_OPEN_TMP_TABLE : HA_OPEN_IGNORE_IF_LOCKED) | ha_open_flags))))
1663 {1641 {
1664 switch (ha_err)1642 switch (ha_err)
1665 {1643 {
@@ -1699,7 +1677,8 @@
1699 char buff[FN_REFLEN];1677 char buff[FN_REFLEN];
1700 myf errortype= ME_ERROR+ME_WAITTANG;1678 myf errortype= ME_ERROR+ME_WAITTANG;
17011679
1702 switch (pass_error) {1680 switch (pass_error)
1681 {
1703 case 7:1682 case 7:
1704 case 1:1683 case 1:
1705 if (db_errno == ENOENT)1684 if (db_errno == ENOENT)
@@ -1722,7 +1701,7 @@
1722 {1701 {
1723 const char *csname= get_charset_name((uint32_t) pass_errarg);1702 const char *csname= get_charset_name((uint32_t) pass_errarg);
1724 char tmp[10];1703 char tmp[10];
1725 if (!csname || csname[0] =='?')1704 if (not csname || csname[0] =='?')
1726 {1705 {
1727 snprintf(tmp, sizeof(tmp), "#%d", pass_errarg);1706 snprintf(tmp, sizeof(tmp), "#%d", pass_errarg);
1728 csname= tmp;1707 csname= tmp;
@@ -1784,120 +1763,48 @@
1784 const charset_info_st * field_charset,1763 const charset_info_st * field_charset,
1785 Field::utype unireg_check,1764 Field::utype unireg_check,
1786 TYPELIB *interval,1765 TYPELIB *interval,
1787 const char *field_name, 1766 const char *field_name,
1788 bool is_unsigned)1767 bool is_unsigned)
1789{1768{
1790 if (! is_nullable)1769 if (is_nullable)
1770 {
1771 null_bit= ((unsigned char) 1) << null_bit;
1772 }
1773 else
1791 {1774 {
1792 null_pos=0;1775 null_pos=0;
1793 null_bit=0;1776 null_bit=0;
1794 }1777 }
1795 else
1796 {
1797 null_bit= ((unsigned char) 1) << null_bit;
1798 }
17991778
1800 switch (field_type)1779 switch (field_type)
1801 {1780 {
1802 case DRIZZLE_TYPE_ENUM:1781 case DRIZZLE_TYPE_ENUM:
1803 return new (&mem_root) Field_enum(ptr,1782 return new (&mem_root) Field_enum(ptr, field_length, null_pos, null_bit, field_name, interval, field_charset);
1804 field_length,
1805 null_pos,
1806 null_bit,
1807 field_name,
1808 interval,
1809 field_charset);
1810 case DRIZZLE_TYPE_VARCHAR:1783 case DRIZZLE_TYPE_VARCHAR:
1811 setVariableWidth();1784 setVariableWidth();
1812 return new (&mem_root) Field_varstring(ptr,field_length,1785 return new (&mem_root) Field_varstring(ptr,field_length, ha_varchar_packlength(field_length), null_pos,null_bit, field_name, field_charset);
1813 ha_varchar_packlength(field_length),
1814 null_pos,null_bit,
1815 field_name,
1816 field_charset);
1817 case DRIZZLE_TYPE_BLOB:1786 case DRIZZLE_TYPE_BLOB:
1818 return new (&mem_root) Field_blob(ptr,1787 return new (&mem_root) Field_blob(ptr, null_pos, null_bit, field_name, this, field_charset);
1819 null_pos,
1820 null_bit,
1821 field_name,
1822 this,
1823 field_charset);
1824 case DRIZZLE_TYPE_DECIMAL:1788 case DRIZZLE_TYPE_DECIMAL:
1825 return new (&mem_root) Field_decimal(ptr,1789 return new (&mem_root) Field_decimal(ptr, field_length, null_pos, null_bit, unireg_check, field_name, decimals);
1826 field_length,
1827 null_pos,
1828 null_bit,
1829 unireg_check,
1830 field_name,
1831 decimals);
1832 case DRIZZLE_TYPE_DOUBLE:1790 case DRIZZLE_TYPE_DOUBLE:
1833 return new (&mem_root) Field_double(ptr,1791 return new (&mem_root) Field_double(ptr, field_length, null_pos, null_bit, unireg_check, field_name, decimals, false, false /* is_unsigned */);
1834 field_length,
1835 null_pos,
1836 null_bit,
1837 unireg_check,
1838 field_name,
1839 decimals,
1840 false,
1841 false /* is_unsigned */);
1842 case DRIZZLE_TYPE_UUID:1792 case DRIZZLE_TYPE_UUID:
1843 return new (&mem_root) field::Uuid(ptr,1793 return new (&mem_root) field::Uuid(ptr, field_length, null_pos, null_bit, field_name);
1844 field_length,
1845 null_pos,
1846 null_bit,
1847 field_name);
1848 case DRIZZLE_TYPE_IPV6:1794 case DRIZZLE_TYPE_IPV6:
1849 return new (&mem_root) field::IPv6(ptr,1795 return new (&mem_root) field::IPv6(ptr, field_length, null_pos, null_bit, field_name);
1850 field_length,
1851 null_pos,
1852 null_bit,
1853 field_name);
1854 case DRIZZLE_TYPE_BOOLEAN:1796 case DRIZZLE_TYPE_BOOLEAN:
1855 return new (&mem_root) field::Boolean(ptr,1797 return new (&mem_root) field::Boolean(ptr, field_length, null_pos, null_bit, field_name, is_unsigned);
1856 field_length,
1857 null_pos,
1858 null_bit,
1859 field_name,
1860 is_unsigned);
1861 case DRIZZLE_TYPE_LONG:1798 case DRIZZLE_TYPE_LONG:
1862 return new (&mem_root) field::Int32(ptr,1799 return new (&mem_root) field::Int32(ptr, field_length, null_pos, null_bit, unireg_check, field_name);
1863 field_length,
1864 null_pos,
1865 null_bit,
1866 unireg_check,
1867 field_name);
1868 case DRIZZLE_TYPE_LONGLONG:1800 case DRIZZLE_TYPE_LONGLONG:
1869 {1801 if (is_unsigned)
1870 if (is_unsigned)1802 return new (&mem_root) field::Size(ptr, field_length, null_pos, null_bit, unireg_check, field_name);
1871 {1803 return new (&mem_root) field::Int64(ptr, field_length, null_pos, null_bit, unireg_check, field_name);
1872 return new (&mem_root) field::Size(ptr,
1873 field_length,
1874 null_pos,
1875 null_bit,
1876 unireg_check,
1877 field_name);
1878 }
1879
1880 return new (&mem_root) field::Int64(ptr,
1881 field_length,
1882 null_pos,
1883 null_bit,
1884 unireg_check,
1885 field_name);
1886 }
1887 case DRIZZLE_TYPE_MICROTIME:1804 case DRIZZLE_TYPE_MICROTIME:
1888 return new (&mem_root) field::Microtime(ptr,1805 return new (&mem_root) field::Microtime(ptr, null_pos, null_bit, unireg_check, field_name, this);
1889 null_pos,
1890 null_bit,
1891 unireg_check,
1892 field_name,
1893 this);
1894 case DRIZZLE_TYPE_TIMESTAMP:1806 case DRIZZLE_TYPE_TIMESTAMP:
1895 return new (&mem_root) field::Epoch(ptr,1807 return new (&mem_root) field::Epoch(ptr, null_pos, null_bit, unireg_check, field_name, this);
1896 null_pos,
1897 null_bit,
1898 unireg_check,
1899 field_name,
1900 this);
1901 case DRIZZLE_TYPE_TIME:1808 case DRIZZLE_TYPE_TIME:
1902 return new (&mem_root) field::Time(ptr, field_length, null_pos, null_bit, field_name);1809 return new (&mem_root) field::Time(ptr, field_length, null_pos, null_bit, field_name);
1903 case DRIZZLE_TYPE_DATE:1810 case DRIZZLE_TYPE_DATE:
@@ -1916,5 +1823,4 @@
1916 version= g_refresh_version;1823 version= g_refresh_version;
1917}1824}
19181825
1919
1920} /* namespace drizzled */1826} /* namespace drizzled */

Subscribers

People subscribed via source and target branches