• R/O
  • SSH
  • HTTPS

tenarai: 提交


Commit MetaInfo

修訂67 (tree)
時間2008-04-01 21:37:09
作者junkikuchi

Log Message

added float column type.

Change Summary

差異

--- trunk/lib/tenarai/db/column.rb (revision 66)
+++ trunk/lib/tenarai/db/column.rb (revision 67)
@@ -53,6 +53,16 @@
5353 end
5454 end
5555
56+ class Float < Column
57+ def execute(command)
58+ if @param[:unsigned]
59+ command.float_unsigned(self)
60+ else
61+ command.float(self)
62+ end
63+ end
64+ end
65+
5666 class String < Column
5767 def initialize(name, param={})
5868 super
--- trunk/lib/tenarai/db/engine.rb (revision 66)
+++ trunk/lib/tenarai/db/engine.rb (revision 67)
@@ -164,6 +164,8 @@
164164 def boolean(col) handler(col); end
165165 def integer(col) handler(col); end
166166 def integer_unsigned(col) handler(col); end
167+ def float(col) handler(col); end
168+ def float_unsigned(col) handler(col); end
167169 def varchar(col) handler(col); end
168170 def char(col) handler(col); end
169171 def text(col) handler(col); end
@@ -207,6 +209,28 @@
207209 @col << self.class::SQL_INT_UNSIG % col.name
208210 end
209211
212+ def float(col)
213+ @col << self.class::SQL_FLOAT % [
214+ col.name,
215+ if col.param[:precision]
216+ "(%d, %d)" % [col.param[:precision], col.param[:scale] || 0]
217+ else
218+ nil
219+ end
220+ ]
221+ end
222+
223+ def float_unsigned(col)
224+ @col << self.class::SQL_FLOAT_UNSIG % [
225+ col.name,
226+ if col.param[:precision]
227+ "(%d, %d)" % [col.param[:precision], col.param[:scale] || 0]
228+ else
229+ nil
230+ end
231+ ]
232+ end
233+
210234 def varchar(col)
211235 @col << self.class::SQL_VARCHAR % [col.name, col.param[:length]]
212236 end
--- trunk/lib/tenarai/db/mysql.rb (revision 66)
+++ trunk/lib/tenarai/db/mysql.rb (revision 67)
@@ -13,6 +13,8 @@
1313 SQL_BOOLEAN = ' %s BOOLEAN'
1414 SQL_INT = ' %s INT'
1515 SQL_INT_UNSIG = ' %s INT UNSIGNED'
16+ SQL_FLOAT = ' %s FLOAT%s'
17+ SQL_FLOAT_UNSIG = ' %s FLOAT%s UNSIGNED'
1618 SQL_VARCHAR = ' %s VARCHAR(%s)'
1719 SQL_CHAR = ' %s CHAR(%s)'
1820 SQL_TEXT = ' %s LONGBLOB'
Show on old repository browser