title: String getting converted to number when inserting it in database through Perl's DBI $sth->execute() function
body: <p>I'm using Perl's DBI and SQLite database (I have DBD::SQLite installed). I have the following code:</p>
  
  <pre><code>my $dbh = DBI-&gt;connect("dbi:SQLite:dbname=$db", "", "", { RaiseError =&gt; 1, AutoCommit =&gt; 1 });
  ...
  my $q = "INSERT OR IGNORE INTO books (identica, book_title) VALUES (?, ?)";
  my $sth = $dbh-&gt;prepare($q);
  $sth-&gt;execute($book_info-&gt;{identica}, $book_info-&gt;{book_title});
  </code></pre>
  
  <p>The problem I have is when <code>$book_info-&gt;{identica}</code> begins with 0's they get dropped and I get a number inserted in the database.</p>
  
  <p>For example, <code>identica</code> of <code>00123</code> will get converted to <code>123</code>.</p>
  
  <p>I know SQLite doesn't have types, so how do I make DBI to insert the <code>identica</code> as string rather than number?</p>
  
  <p>I tried quoting it as <code>"$book_info-&gt;{identica}"</code> when passing to <code>$sth-&gt;execute</code> but that didn't help.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Even if I insert value directly in query it doesn't work:</p>
  
  <pre><code>my $i = $book_info-&gt;{identica};
  my $q = "INSERT OR IGNORE INTO books (identica, book_title) VALUES ('$i', ?)";
  my $sth = $dbh-&gt;prepare($q);
  $sth-&gt;execute($book_info-&gt;{book_title});
  </code></pre>
  
  <p>This still coverts <code>00123</code> to <code>123</code>, and <code>0000000009</code> to <code>9</code>...</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Holy sh*t, I did this on the command line, and I got this:</p>
  
  <pre><code>sqlite&gt; INSERT INTO books (identica, book_title) VALUES ('0439023521', 'a');
  sqlite&gt; select * from books where id=28;
  28|439023521|a|
  </code></pre>
  
  <p>It was dropped by SQLite!</p>
  
  <p>Here is how the schema looks:</p>
  
  <pre><code>CREATE TABLE books (
    id                INTEGER PRIMARY KEY AUTOINCREMENT,
    identica          STRING  NOT NULL,
  );
  
  CREATE UNIQUE INDEX IDX_identica       on books(identica);
  CREATE INDEX IDX_book_title            on books(book_title);
  </code></pre>
  
  <p>Any ideas what is going on?</p>
  
  <p><strong>SOLUTION</strong></p>
  
  <p>It's sqlite problem, see answer by in the comments by Jim. The <code>STRING</code> has to be <code>TEXT</code> in sqlite. Otherwise it treats it as number!</p>
  
  <p>Changing schema to the following solved it:</p>
  
  <pre><code>CREATE TABLE books (
    id                INTEGER PRIMARY KEY AUTOINCREMENT,
    identica          TEXT  NOT NULL,
  );
  </code></pre>