Closed frypan-handler closed 11 years ago
Using the code in the previous issue, I modified it to allow replacing of the *, where previously it would be erased.
Redmine::WikiFormatting::Macros.register do desc "Run SQL query" macro :sql do |obj, args| _sentence = args.join(",") _sentence = _sentence.gsub("\\(", "(") _sentence = _sentence.gsub("\\)", ")") _sentence = _sentence.gsub("\\*", "*") result = ActiveRecord::Base.connection.execute(_sentence) unless result.nil? unless result.num_rows() == 0 column_names = [] for columns in result.fetch_fields.each do column_names += columns.name.to_a end _thead = '<tr>' column_names.each do |column_name| _thead << '<th>' + column_name.to_s + '</th>' end _thead << '</tr>' _tbody = '' result.each_hash do |record| unless record.nil? _tbody << '<tr>' column_names.each do |column_name| _tbody << '<td>' + record[column_name].to_s + '</td>' end _tbody << '</tr>' end end _table = '<table>' << _thead << _tbody << '</table>' result.free return _table else result.free return '0 records returned' end else result.free return 'No result returned' end end end
Plugin updated!
Using the code in the previous issue, I modified it to allow replacing of the *, where previously it would be erased.