嗨,我预先填充分贝这里说 http://docs.rhomobile.com/faq#how-to-pre-populate-client-database ,但我有一个问题,当我做复位DB与默认代码Rhomobile的预先填充DB和复位
def do_reset
Rhom::Rhom.database_full_reset
SyncEngine.dosync
@msg = "Database has been reset."
redirect :action => :index, :query => {:msg => @msg}
end
然后我失去的数据。当我重置时,如何使预填充的数据库等会被加载。 干杯
我想出了这样的解决方案
鉴于do_reset.erb
<%
Antwort.delete_all()
file_name = File.join(Rho::RhoApplication::get_model_path('app','Settings'), 'antwort.txt')
file = File.new(file_name,"r")
aid=0
file.each_line("\n") do |row|
col = row.split("|")
aid=aid+1
@antwort=Antwort.create(
{"aid" => aid, "qid" => col[0],"antwort"=>col[1],"richtig"=>col[2]}
)
qty=file.lineno
break if file.lineno > 3000
end
Questions.delete_all()
file_name = File.join(Rho::RhoApplication::get_model_path('app','Settings'), 'questions.txt')
file = File.new(file_name)
file.each_line("\n") do |row|
col = row.split("|")
@question=Questions.create(
{"id" => col[0], "question" => col[1],"answered"=>'0',"show"=>'1',"tutorial"=>col[4]}
)
break if file.lineno > 1500
end
file.close
@msg="OK"
%>
但是,只有我现在的问题是在文本中的单引号又名“。然后它们会以应用程序的形式显示在三角形中里面像 一样。该怎么办?
我认为,在这种情况下,您将需要使用插入直接填充数据库。您可以创建一组SQL语句并运行它们中的每一个。在数据库重置时创建预填充的数据库。 –
你的意思,而不是SyncEngine.dosync我应该写一个代码,将数据插入数据库?任何想法什么将是最好的方式? CSV? –
是的,这是关闭的。但是,杰弗里在他的回答中如何记住,你可以使用管道分隔的文本,我认为这是一个更好的主意。 –