Skip to content
This repository has been archived by the owner on Dec 11, 2018. It is now read-only.

Commit

Permalink
Fix a bunch of the code
Browse files Browse the repository at this point in the history
  • Loading branch information
beberlei committed May 1, 2012
1 parent 3a5d389 commit d48c9d7
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 24 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -1,3 +1,5 @@
vendor
*.phpunit.xml
*.swp
examples/sharding/vendor
examples/sharding/composer.lock
27 changes: 12 additions & 15 deletions docs/sharding_azure_tutorial.rst
Expand Up @@ -30,7 +30,7 @@ the following content:
{
"require": {
"doctrine/dbal": "2.2.2",
"doctrine/shards": "0.1"
"doctrine/shards": "0.2"
}
}

Expand All @@ -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',
Expand All @@ -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
-------------
Expand Down Expand Up @@ -264,8 +257,7 @@ operation for us:
'LastName' => 'Brehm',
));
$conn->executeUpdate("
DECLARE @orderId INT
$conn->executeUpdate("DECLARE @orderId INT
DECLARE @customerId INT
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -342,6 +337,8 @@ have him create an order.
<?php
// insert_data_aftersplit.php
require_once 'bootstrap.php';
$newCustomerId = 55;
$shardManager->selectShard($newCustomerId);
Expand Down
2 changes: 1 addition & 1 deletion examples/sharding/composer.json
@@ -1,6 +1,6 @@
{
"require": {
"doctrine/dbal": "2.2.2",
"doctrine/dbal": "*",
"doctrine/shards": "0.2"
}
}
5 changes: 0 additions & 5 deletions examples/sharding/create_database.php

This file was deleted.

4 changes: 3 additions & 1 deletion examples/sharding/create_schema.php
Expand Up @@ -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);

2 changes: 1 addition & 1 deletion examples/sharding/insert_data.php
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions examples/sharding/insert_data_aftersplit.php
@@ -1,5 +1,7 @@
<?php
// insert_data_aftersplit.php
require_once 'bootstrap.php';

$newCustomerId = 55;

$shardManager->selectShard($newCustomerId);
Expand Down
2 changes: 2 additions & 0 deletions examples/sharding/split_federation.php
@@ -1,3 +1,5 @@
<?php
// split_federation.php
require_once 'bootstrap.php';

$shardManager->splitFederation(60);
5 changes: 4 additions & 1 deletion lib/Doctrine/Shards/DBAL/SQLAzure/SQLAzureShardManager.php
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
}
}
Expand Down

0 comments on commit d48c9d7

Please sign in to comment.