Permalink
Browse files

Fix a bunch of the code

  • Loading branch information...
1 parent 3a5d389 commit d48c9d77a505ed7d62a29df2db76d8b06668584d @beberlei beberlei committed May 1, 2012
View
@@ -1,3 +1,5 @@
vendor
*.phpunit.xml
*.swp
+examples/sharding/vendor
+examples/sharding/composer.lock
@@ -30,7 +30,7 @@ the following content:
{
"require": {
"doctrine/dbal": "2.2.2",
- "doctrine/shards": "0.1"
+ "doctrine/shards": "0.2"
}
}
@@ -51,9 +51,10 @@ The first thing to start with is setting up Doctrine and the database connection
use Doctrine\DBAL\DriverManager;
use Doctrine\Shards\DBAL\SQLAzure\SQLAzureShardManager;
- require_once "vendor/composer/autoload.php";
+ require_once "vendor/autoload.php";
$conn = DriverManager::getConnection(array(
+ 'driver' => 'pdo_sqlsrv',
'dbname' => 'SalesDB',
'host' => 'tcp:dbname.windows.net',
'user' => 'user@dbname',
@@ -64,21 +65,13 @@ The first thing to start with is setting up Doctrine and the database connection
'distributionType' => 'integer',
)
));
+
$shardManager = new SQLAzureShardManager($conn);
Create Database
---------------
-We can create a new database we use for this federation tutorial. Doctrine
-offers a SchemaManager API to create databases:
-
-.. code-block:: php
-
- <?php
- // create_database.php
- require_once 'bootstrap.php';
-
- $conn->getSchemaManager()->createDatabase('SalesDB');
+Create a new database using the Azure/SQL Azure management console.
Create Schema
-------------
@@ -264,8 +257,7 @@ operation for us:
'LastName' => 'Brehm',
));
- $conn->executeUpdate("
- DECLARE @orderId INT
+ $conn->executeUpdate("DECLARE @orderId INT
DECLARE @customerId INT
@@ -303,7 +295,8 @@ operation for us:
VALUES (@customerId, @orderId, GetDate())
INSERT INTO OrderItems (CustomerID, OrderID, ProductID, Quantity)
- VALUES (@customerId, @orderId, 388, 1)");
+ VALUES (@customerId, @orderId, 388, 1)"
+ );
This puts the data into the currently only existing federation member. We
selected that federation member by picking 0 as distribution value, which is by
@@ -320,6 +313,8 @@ executed this command.
<?php
// split_federation.php
+ require_once 'bootstrap.php';
+
$shardManager->splitFederation(60);
This little script uses the shard manager with a special method only existing
@@ -342,6 +337,8 @@ have him create an order.
<?php
// insert_data_aftersplit.php
+ require_once 'bootstrap.php';
+
$newCustomerId = 55;
$shardManager->selectShard($newCustomerId);
@@ -1,6 +1,6 @@
{
"require": {
- "doctrine/dbal": "2.2.2",
+ "doctrine/dbal": "*",
"doctrine/shards": "0.2"
}
}
@@ -1,5 +0,0 @@
-<?php
-// create_database.php
-require_once 'bootstrap.php';
-
-$conn->getSchemaManager()->createDatabase('SalesDB');
@@ -43,7 +43,9 @@
// Create the Schema + Federation:
$synchronizer = new SQLAzureSchemaSynchronizer($conn, $shardManager);
-$synchronizer->createSchema($schema);
// Or jut look at the SQL:
echo implode("\n", $synchronizer->getCreateSchema($schema));
+
+$synchronizer->createSchema($schema);
+
@@ -23,7 +23,7 @@
"Price" => 10.50,
));
$conn->insert("Products", array(
- "ProductID" => 388,
+ "ProductID" => 389,
"SupplierID" => 1001,
"ProductName" => 'Bypass Filter 400 MHz Low Pass',
"Price" => 10.50,
@@ -1,5 +1,7 @@
<?php
// insert_data_aftersplit.php
+require_once 'bootstrap.php';
+
$newCustomerId = 55;
$shardManager->selectShard($newCustomerId);
@@ -1,3 +1,5 @@
<?php
// split_federation.php
+require_once 'bootstrap.php';
+
$shardManager->splitFederation(60);
@@ -22,6 +22,7 @@
use Doctrine\Shards\DBAL\ShardManager;
use Doctrine\Shards\DBAL\ShardingException;
use Doctrine\DBAL\Connection;
+use Doctrine\DBAL\Types\Type;
/**
* Sharding using the SQL Azure Federations support.
@@ -231,9 +232,11 @@ public function queryAll($sql, array $params = array(), array $types = array())
*/
public function splitFederation($splitDistributionValue)
{
+ $type = Type::getType($this->distributionType);
+
$sql = "ALTER FEDERATION " . $this->getFederationName() . " " .
"SPLIT AT (" . $this->getDistributionKey() . " = " .
- $this->conn->quote($splitDistributionValue);
+ $this->conn->quote($splitDistributionValue, $type->getBindingType());
$this->conn->exec($sql);
}
}

0 comments on commit d48c9d7

Please sign in to comment.