Skip to content

Instantly share code, notes, and snippets.

@rabbl
Created February 27, 2016 21:53
Show Gist options
  • Save rabbl/5fc094da71ae69ade5a6 to your computer and use it in GitHub Desktop.
Save rabbl/5fc094da71ae69ade5a6 to your computer and use it in GitHub Desktop.
// This is working
public function testInsertNullRaster()
{
$conn = $this->entityManager->getConnection();
$stmt = $conn->prepare('SET NAMES \'UTF8\'');
$stmt->execute();
$stmt = $conn->prepare('SELECT NEXTVAL(\'rasters_id_seq\')');
$stmt->execute();
$result = $stmt->fetchAll();
$nextval = $result[0]['nextval'];
$stmt = $conn->prepare("INSERT INTO rasters (id, rast) VALUES (:id,:rast)");
$stmt->execute(array(
':id' => $nextval,
':rast' => null,
));
}
// This is working
public function testInsertNullRaster2()
{
$conn = $this->entityManager->getConnection();
$stmt = $conn->prepare('SET NAMES \'UTF8\'');
$stmt->execute();
$stmt = $conn->prepare('SELECT NEXTVAL(\'rasters_id_seq\')');
$stmt->execute();
$result = $stmt->fetchAll();
$nextval = $result[0]['nextval'];
$stmt = $conn->prepare("INSERT INTO rasters (id, rast) VALUES (?,?)");
$stmt->execute(array(
$nextval,
null
));
}
// This is working
public function testInsertNullRasterWithExecuteQuery()
{
$conn = $this->entityManager->getConnection();
$stmt = $conn->prepare('SET NAMES \'UTF8\'');
$stmt->execute();
$stmt = $conn->prepare('SELECT NEXTVAL(\'rasters_id_seq\')');
$stmt->execute();
$result = $stmt->fetchAll();
$nextval = $result[0]['nextval'];
$stmt = $conn->executeQuery("INSERT INTO rasters (id, rast) VALUES (?,?)",
array($nextval, null),
array(\PDO::PARAM_INT, \PDO::PARAM_NULL)
);
}
// This is working
public function testInsertEmptyRasterWithExecuteQuery()
{
$conn = $this->entityManager->getConnection();
$stmt = $conn->prepare('SET NAMES \'UTF8\'');
$stmt->execute();
$stmt = $conn->prepare('SELECT NEXTVAL(\'rasters_id_seq\')');
$stmt->execute();
$result = $stmt->fetchAll();
$nextval = $result[0]['nextval'];
$stmt = $conn->executeQuery("INSERT INTO rasters (id, rast) VALUES (?, ST_MakeEmptyRaster( 100, 100, 0.0005, 0.0005, 1, 1, 0, 0, 4326))",
array($nextval),
array(\PDO::PARAM_INT)
);
}
// This is not working
public function testInsertEmptyRasterWithExecuteQueryAndParam()
{
$conn = $this->entityManager->getConnection();
$stmt = $conn->prepare('SET NAMES \'UTF8\'');
$stmt->execute();
$stmt = $conn->prepare('SELECT NEXTVAL(\'rasters_id_seq\')');
$stmt->execute();
$result = $stmt->fetchAll();
$nextval = $result[0]['nextval'];
$stmt = $conn->executeQuery("INSERT INTO rasters (id, rast) VALUES (?, ?)",
array($nextval, "ST_MakeEmptyRaster( 100, 100, 0.0005, 0.0005, 1, 1, 0, 0, 4326)"),
array(\PDO::PARAM_INT, \PDO::PARAM_STR)
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment