Ferreteria/v0.6/clade/Sys/Data/Engine/Oper/MyMar

From Woozle Writes Code
< Ferreteria‎ | v0.6‎ | clade‎ | Sys‎ | Data‎ | Engine‎ | Oper
Revision as of 14:09, 27 November 2025 by Woozle (talk | contribs) (Created page with "{{page/clade/v2 |fam= {{!}} align=right {{!}} <code>{{l/ver/clade|Sys\Data\Engine|Oper}}</code> {{!}} align=center {{!}} ⇒ <code>{{l/ver/clade|Sys\Data\Engine\Oper|MyMar}}</code> ⇒ {{!}} align=left {{!}} <poem> <code>{{l/ver/clade|Sys\Data\Engine\Oper\MyMar|Maria}}</code> <code>{{l/ver/clade|Sys\Data\Engine\Oper\MyMar|MySQL}}</code> </poem> |alia= {{!-!}} '''ActionIface''' {{!!}} <code>{{l/ver/clade/full|Sys\Events|ItWent}} {{!-!}} '''Base'''* [ca,i] {...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
clade: Sys\Data\Engine\Oper\MyMar
Clade Family
Oper MyMar
Clade Aliases
Alias Clade
ActionIface Sys\Events\ItWent
Base* [ca,i] Sys\Data\Engine\Oper
BkupModeEnum Sys\Data\Engine\aux\ActionRq\Admin\aux\FileFormat
CommOp* [c,i] Sys\Data\Engine\aux\msgs\Maria\ItWent
DataReqIface Sys\Data\Engine\aux\CommRq
MemBufferClass IO\Aspect\Connx\Buffer\InMem
PlayerIface Data\Base\Result\Player
QObj* [c,i] Data\Mem\QVar\Obj
RecvBuffClass IO\Aspect\Connx\Buffer\File\Writer
SchemaClass Sys\Data\Engine\schema\Ops\MyMar
Schemas* [c,i] Sys\Data\aux\list\Schemas
ScribeClass Sys\Data\Xfer\Scribe\MySQL
Subpages

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