You must use a second column, of type text. series_index is a builtin and contains data of type number (float I think), so the database will automatically remove the leading zeroes when storing it.

The second column gets around that issue.
OTOH, that is indeed the correct way of changing which column you use to store the value.
So, what this script does is set the number of leading zeroes based on the highest series_index value in a particular series. If the series has books 1-9, no leading zeroes. If the series goes from 1-99, one leading zero for books 1-9. And so on.