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
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|
# 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}")
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"
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