Skip to content

Commit

Permalink
Allow quotes around 'TableName' in sqlite schema
Browse files Browse the repository at this point in the history
  • Loading branch information
agrare committed Nov 4, 2024
1 parent 2873fdc commit 5f0c394
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/db/MiqSqlite/MiqSqlite3Table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def decodeSchema
return if @type != "table" || @name[0..6] == "sqlite_" # Names beginning with sqlite_ are internal to engine
@columns = []
sql = @sql.gsub(/[\n\r]/, "")
re1 = /\s*CREATE\s+TABLE\s+(\w+)\s*\((.*)\)\s*/
re1 = /\s*CREATE\s+TABLE\s+'?(\w+)'?\s*\((.*)\)\s*/
m = re1.match(sql)
tname = m[1].to_s.chomp
raise "Inconsistent Table Name" if tname != @name
Expand Down
Binary file added spec/db/MiqSqlite/rpmdb-empty.sqlite
Binary file not shown.
87 changes: 87 additions & 0 deletions spec/db/MiqSqlite/rpmdb_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
require 'db/MiqSqlite/MiqSqlite3'

describe MiqSqlite3DB::MiqSqlite3 do
let(:fname) { "#{File.dirname(__FILE__)}/rpmdb-empty.sqlite" }
let(:db) { MiqSqlite3DB::MiqSqlite3.new(fname) }

after do
db.close
end

it "#pageSize" do
expect(db.pageSize).to eq(4_096)
end

it "#maxLocal" do
expect(db.maxLocal).to eq(1_002)
end

it "#minLocal" do
expect(db.minLocal).to eq(489)
end

it "#usableSize" do
expect(db.usableSize).to eq(4_096)
end

it "#maxLeaf" do
expect(db.maxLeaf).to eq(4_061)
end

it "#minLeaf" do
expect(db.minLeaf).to eq(489)
end

it "#npages" do
expect(db.npages).to eq(52)
end

it "#each_page" do
expect(db.each_page { |pg| pg }.count).to eq(52)
end

it "#readPage" do
expect(db.readPage(1)).to start_with("SQLite format 3")
end

it "#size" do
expect(db.size).to eq(File.size(fname))
end

it "#table_names" do
expected = %w[
Basenames
Conflictname
Dirnames
Enhancename
Filetriggername
Group
Installtid
Name
Obsoletename
Packages
Providename
Recommendname
Requirename
Sha1header
Sigmd5
Suggestname
Supplementname
Transfiletriggername
Triggername
sqlite_sequence
]

expect(db.table_names).to match_array(expected)
end

it "#getTable" do
packages_table = db.getTable('Packages')

expect(packages_table).to be_kind_of(MiqSqlite3DB::MiqSqlite3Table)
expect(packages_table).to have_attributes(
:name => "Packages",
:type => "table"
)
end
end

0 comments on commit 5f0c394

Please sign in to comment.