If you've ever had to wonder how much this whole beautiful data plate really weighs, here's binsizedb for you. It's a small function, it makes a lot of sense.
What is she doing? Returns the real, binary (i.e. in bytes) size of a database or a specific table. No magic, just facts.
It works simply: do you give her either the dbid (that is, the identifier of the open database opened by the function
opendb),
or a table (if you want to know about a specific table, an open function opentable).
It's just one thing. No need to try to feed her both options at once — she won't choose, she'll fall with an error.
Next, binsizedb does what programmers call a "not-so-fun data loop." She goes through each table (if you gave her a database),
or each record (if you gave her a table), looks at all the columns and calculates how many bytes each of them occupies.
Something like this:
The INTEGER type? Okay, we consider it a fixed size.
A VARCHAR type with text? First, we look at what the string is, then we calculate its length in bytes.
And so it goes, column by column. Line by line. Everything adds up. As a result, you get a dry but honest figure — how much it all weighs in binary terms.
No poetry. Just an accurate calculation, down to a byte. It's a great tool if you want to understand the load, check optimization, or just know what kind of marble elephant you have growing in the corner of the base.
Help on built-in functions
The rules of programming scripts
Programm options
Color constants