[Title] sqlite support datetime now
authorjiil.hyoun <jiil.hyoun@samsung.com>
Mon, 26 Nov 2012 10:09:50 +0000 (19:09 +0900)
committerjiil.hyoun <jiil.hyoun@samsung.com>
Mon, 26 Nov 2012 10:09:50 +0000 (19:09 +0900)
[Type] Bugfix
[Module] Toolchain /
[Priority] Major
[Jira#]
[Redmine#]
[Problem]
[Cause]
[Solution]
[TestCase]

Change-Id: I61ea2e196a870c4ab202aff115f3adcaee8b4d98

src/build_server/BuildServer.rb
src/build_server/CommonJob.rb
src/build_server/JobManager.rb

index 72fe4f52d598d1421aa82928dc6672227959f665..995c0db2b0768475bb3f4f41c1a915c84d9cade9 100644 (file)
@@ -184,6 +184,18 @@ class BuildServer
                end
        end
 
+       def db_inc
+               return (@db_dsn =~ /^Mysql/i) ? "AUTO_INCREMENT" : "AUTOINCREMENT"
+       end
+
+       def db_post_fix
+               return (@db_dsn =~ /^Mysql/i) ? "ENGINE = INNODB DEFAULT CHARSET = UTF8" : ""
+       end
+
+       def db_now
+               return (@db_dsn =~ /^Mysql/i) ? "NOW()" : "datetime('now')"
+       end
+
        # start server daemon
        def start
                # set build cache dir
@@ -579,17 +591,9 @@ class BuildServer
        def create_db()
                gen_db()
                result = get_db_connection() do |db|
-                       case @db_dsn
-                       when /^SQLite3:/ then
-                               inc="AUTOINCREMENT"
-                               post_fix=""
-                       when /^Mysql:/ then
-                               inc="AUTO_INCREMENT"
-                               post_fix="ENGINE = INNODB DEFAULT CHARSET = UTF8"
-                       else
-                               inc="AUTOINCREMENT"
-                               post_fix=""
-                       end
+                       inc = db_inc
+                       post_fix = db_post_fix
+                       now = db_now
 
                        # remove table
                        db.tables.each do |table|
index 23b8ba376a741e29be6b2c1698b35f059a3997c2..52fdbbc3ef1609038702920daa15b20f8ae3de5e 100644 (file)
@@ -216,7 +216,7 @@ class CommonJob
 
        # save to db
        public
-       def save(db)
+       def save(db, now)
 
                prj_id = @project.nil? ? "NULL" : @project.get_project_id()
                row=db.select_one("SELECT * FROM jobs WHERE id=#{@id}")
@@ -226,7 +226,7 @@ class CommonJob
                        dist_id = PackageDistribution.get_distribution_id(db, get_distribution_name())
                        parent_id = @parent.nil? ? "NULL" : @parent.id
                        db.do "INSERT INTO jobs(id,project_id,user_id,supported_os_id, distribution_id, parent_job_id,jtype,status,start_time) 
-                               VALUES (#{@id},#{prj_id},#{@user_id},#{os_id},#{dist_id},#{parent_id},'#{@type}','#{@status}', NOW())"
+                               VALUES (#{@id},#{prj_id},#{@user_id},#{os_id},#{dist_id},#{parent_id},'#{@type}','#{@status}',#{now})"
                else
                        remote_bs_id = (@type == "BUILD" and not get_remote_server().nil?) ? 
                                get_remote_server().id : "NULL"
@@ -239,7 +239,7 @@ class CommonJob
                                WHERE id=#{@id}"
                        if @status == "FINISHED" or @status == "ERROR" or @status == "CANCELED" then
                                @end_time = Time.now.strftime("%F %T")
-                               db.do "UPDATE jobs SET end_time=NOW() WHERE id=#{@id}"
+                               db.do "UPDATE jobs SET end_time=#{now} WHERE id=#{@id}"
                        end
                end
        end
index 0ad949e12349a40ccff69f5b94f25cf25fefa421..9dc822e51bd4e95f022ea8532561ece38b2e0502 100644 (file)
@@ -457,8 +457,9 @@ class JobManager
 
 
        def save_job_status(job)
+               now = @server.db_now
                result = @server.get_db_connection() do |db|
-                       return job.save(db)
+                       return job.save(db, now)
                end
 
                return result