<commit_before><?php

namespace Good\Memory\SQL;

use Good\Memory\Database as Database;

use Good\Memory\SQLStorage;
use Good\Memory\SQLPostponedForeignKey;
use Good\Manners\Storable;
use Good\Manners\StorableVisitor;

class Inserter implements StorableVisitor
{
    private $db;
    private $storage;
    
    private $sql;
    private $values;
    private $first;
    
    private $inserting;
    private $postponed;
    
    public function __construct(SQLStorage $storage, Database\Database $db)
    {
        $this->db = $db;
        $this->storage = $storage;
        $this->postponed = array();
    }
    
    
    public function insert($datatypeName, Storable $value)
    {
        $this->sql = 'INSERT INTO ' . $this->storage->tableNamify($datatypeName) . ' (';
        $this->values = 'VALUES (';
        $this->first = true;
        
        $this->inserting = $value;
        
        $value->setNew(false);
        $value->setStorage($this->storage);
        
        $value->acceptStorableVisitor($this);
        
        $this->sql .= ') ';
        $this->sql .= $this->values . ')';
        
        $this->db->query($this->sql);
        $value->setId($this->db->getLastInsertedId());
        $value->clean();
    }

    private function comma()
    {
        if ($this->first)
        {
            $this->first = false;
        }
        else
        {
            $this->sql .= ', ';
            $this->values .= ', ';
        }
    }<commit_msg>[#113] Also do typecasting for id upon insert<commit_after><?php

namespace Good\Memory\SQL;

use Good\Memory\Database as Database;

use Good\Memory\SQLStorage;
use Good\Memory\SQLPostponedForeignKey;
use Good\Manners\Storable;
use Good\Manners\StorableVisitor;

class Inserter implements StorableVisitor
{
    private $db;
    private $storage;
    
    private $sql;
    private $values;
    private $first;
    
    private $inserting;
    private $postponed;
    
    public function __construct(SQLStorage $storage, Database\Database $db)
    {
        $this->db = $db;
        $this->storage = $storage;
        $this->postponed = array();
    }
    
    
    public function insert($datatypeName, Storable $value)
    {
        $this->sql = 'INSERT INTO ' . $this->storage->tableNamify($datatypeName) . ' (';
        $this->values = 'VALUES (';
        $this->first = true;
        
        $this->inserting = $value;
        
        $value->setNew(false);
        $value->setStorage($this->storage);
        
        $value->acceptStorableVisitor($this);
        
        $this->sql .= ') ';
        $this->sql .= $this->values . ')';
        
        $this->db->query($this->sql);
        $value->setId(\strval($this->db->getLastInsertedId()));
        $value->clean();
    }

    private function comma()
    {
        if ($this->first)
        {
            $this->first = false;
        }
        else
        {
            $this->sql .= ', ';
            $this->values .= ', ';
        }
    }
{'fraction_non_alphanumeric': 0.1506895391860074, 'fraction_numerical': 0.0010090817356205853, 'mean_word_length': 1.9185475956820413, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 57, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7220449', 'n_tokens_mistral': 920, 'n_tokens_neox': 910, 'n_words': 165}