Skip to content

Commit

Permalink
Add autoincrement
Browse files Browse the repository at this point in the history
  • Loading branch information
pvcarrera committed Nov 25, 2011
1 parent e551fa9 commit d4a730c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/MySQLConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@ public function emptyDatabase() {
}
}

public function addAutoInc($table){
$this->openConnection();

$this->query("ALTER TABLE {$table}
ADD id smallint(10)
AUTO_INCREMENT
KEY
FIRST"
);

$this->closeConnection();
}

private function getTables() {
$this->openConnection();
$result = mysql_query("SHOW TABLES", $this->connection);
Expand Down
14 changes: 14 additions & 0 deletions test/MYSQLConnectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,18 @@ public function test_insert(
$this->assertEquals($expectedReturn, $this->connection->query($selectQuery));
}

public function test_double_insert(
) {
$this->connection->addAutoInc("tabla");
$this->connection->query("INSERT INTO tabla(campo1, campo2) VALUES ('valor1', 'valor2')");
$this->connection->query("INSERT INTO tabla(campo1, campo2) VALUES ('valor1', 'valor2')");
$this->assertEquals(
array(
array("id" => 1, "campo1" => "valor1", "campo2" =>"valor2"),
array("id" => 2, "campo1" => "valor1", "campo2" =>"valor2")
),
$this->connection->query("SELECT * FROM tabla")
);
}

}

0 comments on commit d4a730c

Please sign in to comment.