Ferreteria/v0.6/clade/Sys/Data/Engine/aux/ActionRq/Admin/ToDbConn: Difference between revisions

From Woozle Writes Code
< Ferreteria‎ | v0.6‎ | clade‎ | Sys‎ | Data‎ | Engine‎ | aux‎ | ActionRq‎ | Admin
Jump to navigation Jump to search
(Created page with "{{page/clade/v2 |fam= {{!}} align=right {{!}} {{l/ver/clade|Sys\Data\Engine\aux\ActionRq|Admin}} {{!}} align=center {{!}} → {{l/ver/clade|Sys\Data\Engine\aux\ActionRq\Admin|ToDbConn}} → {{!}} align=left {{!}} ''(TBD)'' |alia= {{!-!}} '''Base'''* [c,i] {{!!}} {{l/ver/clade/full|p=ferreteria|Sys\Data\Engine\aux\ActionRq|Admin}} }} ==About== * '''Parallel''': {{l/same|ToDbOper}} ==Status== * '''{{fmt/date|2025|10|25}}''' under construction")
 
No edit summary
 
(2 intermediate revisions by the same user not shown)
Line 10: Line 10:
}}
}}
==About==
==About==
* '''Parallel''': {{l/same|ToDbOper}}
* '''Parallels''':
** {{l/same|ToSchema}}
** <s>{{l/same|ToDbOper}}</s> Removed on {{fmt/date|2025|10|26}}
==Status==
==Status==
* '''{{fmt/date|2025|10|25}}''' under construction
* '''{{fmt/date|2025|10|25}}''' under construction
* '''{{fmt/date|2025|10|26}}''' complete-ish, but still refactoring because stuff doesn't work yet
==Code==
''as of {{fmt/date|2025|11|10}}''
{{fmt/php/block|1=
interface iToDbConn {
    // objects
    function QODbOper() : QDbOperIface;
}
trait tToDbConn /* implements iToDbConn */ {
    // ++ REGISTRY ++ //
    // SHORTCUT
    protected function DbasesOArray() : ObjListIface { return ConnAdmin::ObjectRoster(); }
    // -- REGISTRY -- //
    // ++ OBJECTS ++ /
    private $qoOper = NULL;
    public function QODbOper() : QDbOperIface {
        $qoOper = $this->qoOper;
        if (is_null($qoOper)) {
            $qoOper = QDbOperClass::AsNew();
            $this->qoOper = $qoOper;
        }
        $qoConn = $this->QODbConn();
        $ok = $qoConn->HasIt();
        $oItWent = $qoConn->HowItWent();
        $oItWent->SetOkay($ok);
        if ($ok) {
            $oConn = $qoConn->GetIt();
            $oOper = $oConn->OOper();
            $qoOper->SetIt($oOper);
        }
        $qoOper->HowItWent()->CopyFrom($oItWent);
        return $qoOper;
    }
    private $qoConn = NULL;
    public function QODbConn() : QDbConnIface {
        $qoConn = $this->qoConn;
        $doFetch = FALSE;
        if (is_null($qoConn)) {
            #$qoConn = QDbConnClass::AsNew();
            #$this->qoConn = $qoConn;
            $doFetch = TRUE;
        } elseif (!$qoConn->HasIt()) {
            $this->AmHere();
            $doFetch = TRUE;
        }
        if ($doFetch) {
            $qoConn = $this->FetchDBConn();
            $this->qoConn = $qoConn;
        }
        return $qoConn;
    }
    private $oDBC=NULL;
    // ASSUMES: QODbConn() is successful
    protected function ODbConn(?ConnIface $o=NULL) : ConnIface {
        return is_object($o) ? ($this->oDBC = $o) : ($this->oDBC ?? ($this->oDBC = $this->QODbConn()->GetIt()));
    }
    protected function FetchDbConn() : QDbConnIface {
        $oScrn = self::Screen();
        $qoConn = QDbConnClass::AsNew();
        $oItWent = $qoConn->HowItWent();
        // STEP 1: retrieve the name for the requested DB (if any)
        $qsName = $this->QDbConnSlug();
        $didFind = FALSE;
        if ($qsName->HasIt()) {
            $sName = $qsName->GetIt();
            if ($sName !== '') {
                $didFind = TRUE;
            }
        } else {
            $oItWent->SetError($oItWent::N_ERR_DB_SLUG);
            $oItWent->AddMsgString(self::Screen()->ErrorIt('No DB connection-name specified.'));
        }
        if ($didFind) {
        // STEP 2: try to get the DB connection spec object for that name:
            $ftName = $oScrn->BoldIt($sName);
            $oItWent->AddMsgString($oScrn->GreenIt("Using")." DB connection [$ftName].");
#            echo ConnAdmin::ReflectSelf()->Report();
            $oaDBs = ConnAdmin::ObjectRoster();
            $osDB = $oaDBs->QryIt($sName);
            if ($osDB->HasIt()) {
                $oDB = $osDB->GetIt();
                $qoConn->SetIt($oDB);
                $oItWent->SetOkay(TRUE);
            } else {
                $noFind = TRUE;
                $oItWent->SetError($oItWent::N_ERR_DB_DEFN);
                $oItWent->AddMsgString($oScrn->ErrorIt('Input Error').": Could not find DB access specs for [$ftName].");
            }
        }
        /*
        if ($noFind) {
            echo $oaDBs->ReflectThis()->Report();
            echo 'Available:'.CRLF;
            echo $oaDBs->Debug()->Render();
            die();
            // TODO: better error-handling
        }
        */
        return $qoConn;
    }
    // -- OBJECTS -- /
}
}}
===Removed===
===={{fmt/date|2025|10|26}}====
{{fmt/php/block|1=
    // ACTION: tries to retrieve the slug-requested DB Connection object from the db registry
    // 2025-10-26 old version
    protected function FetchDbConn() : QDbConnIface {
        $osDbSlug = $this->QDbConnSlug();
        $doListFiles = FALSE;  // flip this on if the user needs it
        $qoDB = QDbConnClass::AsNew();
        if ($osDbSlug->HasIt()) {
            // Get DB Connection slug for UI display:
            $sDbSlug = $osDbSlug->GetIt();
            // TODO: Look up the DB object (there IS code for this, somewhere...)
            $oaDBs = $this->DbasesOArray();
            #echo 'oaDBs CLASS: '.get_class($oaDBs).CRLF;
            $qoDbConn = $oaDBs->QryIt($sDbSlug);
            if ($qoDbConn->HasIt()) {
                $oDbConn = $qoDbConn->GetIt();
                $qoDB->SetIt($oDbOper);
            }
        }
        return $qoDB;
    }
}}

Latest revision as of 19:59, 10 November 2025

clade: Sys\Data\Engine\aux\ActionRq\Admin\ToDbConn
Clade Family
Admin ToDbConn (TBD)
Clade Aliases
Alias Clade
Base* [c,i] Sys\Data\Engine\aux\ActionRq\Admin
Subpages

About

Status

  • 2025-10-25 under construction
  • 2025-10-26 complete-ish, but still refactoring because stuff doesn't work yet

Code

as of 2025-11-10

interface iToDbConn {
    // objects
    function QODbOper() : QDbOperIface;
}
trait tToDbConn /* implements iToDbConn */ {

    // ++ REGISTRY ++ //

    // SHORTCUT
    protected function DbasesOArray() : ObjListIface { return ConnAdmin::ObjectRoster(); }

    // -- REGISTRY -- //
    // ++ OBJECTS ++ /

    private $qoOper = NULL;
    public function QODbOper() : QDbOperIface {
        $qoOper = $this->qoOper;
        if (is_null($qoOper)) {
            $qoOper = QDbOperClass::AsNew();
            $this->qoOper = $qoOper;
        }
        $qoConn = $this->QODbConn();
        $ok = $qoConn->HasIt();
        $oItWent = $qoConn->HowItWent();
        $oItWent->SetOkay($ok);
        if ($ok) {
            $oConn = $qoConn->GetIt();
            $oOper = $oConn->OOper();
            $qoOper->SetIt($oOper);
        }
        $qoOper->HowItWent()->CopyFrom($oItWent);
        return $qoOper;
    }

    private $qoConn = NULL;
    public function QODbConn() : QDbConnIface {
        $qoConn = $this->qoConn;
        $doFetch = FALSE;
        if (is_null($qoConn)) {
            #$qoConn = QDbConnClass::AsNew();
            #$this->qoConn = $qoConn;
            $doFetch = TRUE;
        } elseif (!$qoConn->HasIt()) {
            $this->AmHere();
            $doFetch = TRUE;
        }
        if ($doFetch) {
            $qoConn = $this->FetchDBConn();
            $this->qoConn = $qoConn;
        }
        return $qoConn;

    }
    private $oDBC=NULL;
    // ASSUMES: QODbConn() is successful
    protected function ODbConn(?ConnIface $o=NULL) : ConnIface {
        return is_object($o) ? ($this->oDBC = $o) : ($this->oDBC ?? ($this->oDBC = $this->QODbConn()->GetIt()));
    }

    protected function FetchDbConn() : QDbConnIface {
        $oScrn = self::Screen();
        $qoConn = QDbConnClass::AsNew();
        $oItWent = $qoConn->HowItWent();

        // STEP 1: retrieve the name for the requested DB (if any)

        $qsName = $this->QDbConnSlug();
        $didFind = FALSE;
        if ($qsName->HasIt()) {
            $sName = $qsName->GetIt();
            if ($sName !== '') {
                $didFind = TRUE;
            }
        } else {
            $oItWent->SetError($oItWent::N_ERR_DB_SLUG);
            $oItWent->AddMsgString(self::Screen()->ErrorIt('No DB connection-name specified.'));
        }

        if ($didFind) {

        // STEP 2: try to get the DB connection spec object for that name:

            $ftName = $oScrn->BoldIt($sName);
            $oItWent->AddMsgString($oScrn->GreenIt("Using")." DB connection [$ftName].");

#            echo ConnAdmin::ReflectSelf()->Report();

            $oaDBs = ConnAdmin::ObjectRoster();
            $osDB = $oaDBs->QryIt($sName);
            if ($osDB->HasIt()) {
                $oDB = $osDB->GetIt();
                $qoConn->SetIt($oDB);
                $oItWent->SetOkay(TRUE);
            } else {
                $noFind = TRUE;
                $oItWent->SetError($oItWent::N_ERR_DB_DEFN);
                $oItWent->AddMsgString($oScrn->ErrorIt('Input Error').": Could not find DB access specs for [$ftName].");
            }
        }
        /*
        if ($noFind) {
            echo $oaDBs->ReflectThis()->Report();
            echo 'Available:'.CRLF;
            echo $oaDBs->Debug()->Render();
            die();
            // TODO: better error-handling
        }
        */
        return $qoConn;
    }

    // -- OBJECTS -- /
}

Removed

2025-10-26

// ACTION: tries to retrieve the slug-requested DB Connection object from the db registry
    // 2025-10-26 old version
    protected function FetchDbConn() : QDbConnIface {
        $osDbSlug = $this->QDbConnSlug();
        $doListFiles = FALSE;   // flip this on if the user needs it
        $qoDB = QDbConnClass::AsNew();
        if ($osDbSlug->HasIt()) {
            // Get DB Connection slug for UI display:
            $sDbSlug = $osDbSlug->GetIt();

            // TODO: Look up the DB object (there IS code for this, somewhere...)
            $oaDBs = $this->DbasesOArray();
            #echo 'oaDBs CLASS: '.get_class($oaDBs).CRLF;
            $qoDbConn = $oaDBs->QryIt($sDbSlug);
            if ($qoDbConn->HasIt()) {
                $oDbConn = $qoDbConn->GetIt();
                $qoDB->SetIt($oDbOper);
            }
        }
        return $qoDB;
    }