Ferreteria/v0.6/clade/Sys/Data/Engine/Oper/MyMar
Jump to navigation
Jump to search
| ||||||||||||||||||||||||||||||||||||
About
- Purpose: class for ops that are done the same/identically in MariaDB and MySQL (and any other compatible engines that turn up).
History
- 2025-05-30 started
- 2025-06-01 moved all of xMaria up here, though some of it may be Maria-tuned (suboptimal for MySQL).
- This stuff can be fine-tuned later.
- 2025-06-10 adding
EngineOpen()/EngineShut()
Functions
Code
interface iMyMar extends BaseIface {
// LIFECYCLE
function EngineOpen(string $sAddr, string $sPass, ?string $sSchema, ?int $nPort) : ActionIface;
function EngineShut() : ActionIface;
// INFO
function SchemaExists(string $sName) : bool; // 2025-05-30 Eventually, will want a base-class for all multi-schema engines.
}
abstract class caMyMar extends BaseClass implements iMyMar {
// ++ CONFIG ++ //
protected function CommOpClass() : string { return CommOpClass::class; } // specialize later
protected function SchemaClass() : string { return SchemaClass::class; }
protected function ScribeClass() : string { return ScribeClass::class; }
// -- CONFIG -- //
// ++ SETTINGS ++ //
private $eFmt = BkupModeEnum::USE_SQL; // DEFAULT
public function DataFormat(?BkupModeEnum $eMode=NULL) : BkupModeEnum { return is_object($eMode) ? ($this->eFmt = $eMode) : $this->eFmt; }
// -- SETTINGS -- //
// ++ LIFECYCLE ++ //
public function EngineOpen(string $sAddr, string $sPass, ?string $sSchema, ?int $nPort) : ActionIface {
#$oAct = new ($this->ActionClass()); // result object
$oAct = $this->NewAction();
$onDB = new mysqli($sAddr,$sUser,$sPass,$sSchema,$nPort); // open the DB connection
if (is_object($onDB)) {
$oAct->SetOkay(TRUE);
$this->QNative()->SetIt($onDB);
} else {
// 2022-01-26 probably want a method to do all this
$oAct->SetOkay(FALSE);
$oAct->SetNumber($this->ErrorNumber());
$oAct->AddMsgString($this->ErrorMessage());
}
return $oAct;
}
public function EngineShut() : ActionIface {
// close endpoint-to-engine connection
$ok = $this->QNative()->GetIt()->close();
// close code-to-endpoint connection
#$oAct = new ($this->ActionClass());
$oAct = $this->NewAction();
$oAct->SetOkay($ok);
return $oAct;
}
// -- LIFECYCLE -- //
// ++ ACTION: UI requests ++ //
public function DoDataRequest(DataReqIface $oReq) : PlayerIface {
$this->Open();
$sql = $oReq->SQL();
#echo "SQL: $sql".CRLF;
$onRes = $this->QNative()->GetIt()->query($sql);
$oReq->Action()->SetOkay(is_object($onRes));
$scScribe = $this->ScribeClass();
# echo $oReq->ReflectThis()->Report();
$oScribe = $scScribe::FromRequestAndNative($oReq,$onRes);
$oPlay = $oReq->MakePlayer($oScribe);
$this->Shut();
return $oPlay;
}
// ++ ACTION: Schema info ++ //
private $oaSchemas = NULL;
public function SchemaList() : SchemasIface { return $this->oaSchemas ?? ($this->oaSchemas = $this->NewSchemaList()); }
public function SchemaExists(string $sName) : bool { return $this->SchemaList()->HasIt($sName); }
protected function NewSchemaList() : SchemasIface {
#$this->AmHere("GENERATING SCHEMA LIST");
$oConn = $this->OConn(); // get (remote