Skip to content

Commit

Permalink
Merge pull request #16 from stephenlake/patch-2
Browse files Browse the repository at this point in the history
Fix #6 for both mysql and postgres - my mistake 💩
  • Loading branch information
igaster authored Sep 13, 2018
2 parents efe28fa + 8b7f583 commit adbdabb
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/commands/seedGeoFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@ class seedGeoFile extends Command
protected $description = 'Load + Parse + Save to DB a geodata file.';

private $pdo;
private $driver;

public function __construct() {
parent::__construct();

$connection = config('database.default');
$this->driver = strtolower(config("database.connections.{$connection}.driver"));

$this->pdo = \DB::connection()->getPdo(\PDO::FETCH_ASSOC);
if (!\Schema::hasTable('geo'))
return;
Expand Down Expand Up @@ -139,7 +144,12 @@ public function handle() {

// Store Tree in DB
$this->info("Writing in Database</info>");
$stmt = $this->pdo->prepare("INSERT INTO geo (\"id\", \"parent_id\", \"left\", \"right\", \"depth\", \"name\", \"alternames\", \"country\", \"level\", \"population\", \"lat\", \"long\") VALUES (:id, :parent_id, :left, :right, :depth, :name, :alternames, :country, :level, :population, :lat, :long)");

if ($this->driver == 'mysql') {
$stmt = $this->pdo->prepare("INSERT INTO geo (`id`, `parent_id`, `left`, `right`, `depth`, `name`, `alternames`, `country`, `level`, `population`, `lat`, `long`) VALUES (:id, :parent_id, :left, :right, :depth, :name, :alternames, :country, :level, :population, :lat, :long)");
} else {
$stmt = $this->pdo->prepare("INSERT INTO geo (\"id\", \"parent_id\", \"left\", \"right\", \"depth\", \"name\", \"alternames\", \"country\", \"level\", \"population\", \"lat\", \"long\") VALUES (:id, :parent_id, :left, :right, :depth, :name, :alternames, :country, :level, :population, :lat, :long)");
}

$count = 0;
$totalCount = count($this->geoItems->items);
Expand Down

0 comments on commit adbdabb

Please sign in to comment.