Skip to content

Commit 6bad15e

Browse files
committed
Fixed MySQL insert logic
1 parent bf4bcb4 commit 6bad15e

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/SOFe/Capital/Database/LabelManager.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use poggit\libasynql\generic\GenericVariable;
1010
use poggit\libasynql\result\SqlChangeResult;
1111
use poggit\libasynql\result\SqlSelectResult;
12+
use poggit\libasynql\SqlDialect;
1213
use poggit\libasynql\SqlError;
1314
use poggit\libasynql\SqlThread;
1415
use Ramsey\Uuid\UuidInterface;
@@ -17,6 +18,7 @@
1718

1819
final class LabelManager {
1920
private DataConnector $conn;
21+
/** @var SqlDialect::* */
2022
private string $dialect;
2123

2224
/**
@@ -75,8 +77,12 @@ public function update(UuidInterface $id, string $name, string $value) : Generat
7577
* @return VoidPromise
7678
*/
7779
public function set(UuidInterface $id, string $name, string $value) : Generator {
80+
$queryString = match ($this->dialect) {
81+
SqlDialect::SQLITE => "INSERT OR REPLACE INTO {$this->labelTable} (id, name, value) VALUES (:id, :name, :value);",
82+
SqlDialect::MYSQL => "INSERT INTO {$this->labelTable} (id, name, value) VALUES (:id, :name, :value) ON DUPLICATE KEY UPDATE value = :value;",
83+
};
7884
yield from QueryBuilder::new()
79-
->addQuery("INSERT OR REPLACE INTO {$this->labelTable} (id, name, value) VALUES (:id, :name, :value);", SqlThread::MODE_CHANGE)
85+
->addQuery($queryString, SqlThread::MODE_CHANGE)
8086
->addParam("id", GenericVariable::TYPE_STRING, $id->toString())
8187
->addParam("name", GenericVariable::TYPE_STRING, $name)
8288
->addParam("value", GenericVariable::TYPE_STRING, $value)

0 commit comments

Comments
 (0)