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

From Woozle Writes Code
< Ferreteria‎ | v0.6‎ | clade‎ | Sys‎ | Data‎ | Engine‎ | aux‎ | ActionRq‎ | Admin
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
{{page/clade}}
{{page/clade/v2
{| style="border: solid 1px black; float: right;"
|fam=
! colspan=3 | Clade Family
{{!}} align=right {{!}} {{l/ver/clade|Sys\Data\Engine\aux\ActionRq|Admin}}
|-
{{!}} align=center {{!}} &rarr; {{l/ver/clade|Sys\Data\Engine\aux\ActionRq\Admin|ToDbOper}}
| align=right | {{l/ver/clade|Sys\Data\Engine\aux\ActionRq|Admin}}
{{!}} align=left {{!}}
| &rarr; {{l/ver/clade|Sys\Data\Engine\aux\ActionRq\Admin|ToDbOper}}
|
&rarr; {{l/ver/clade|Sys\Data\Engine\aux\AdminRq\ToDbOper|EngDbExport}}<br>
&rarr; {{l/ver/clade|Sys\Data\Engine\aux\AdminRq\ToDbOper|EngDbExport}}<br>
&rarr; {{l/ver/clade|Sys\Data\Engine\aux\AdminRq\ToDbOper|EngDbScList}}<br>
&rarr; {{l/ver/clade|Sys\Data\Engine\aux\AdminRq\ToDbOper|EngDbScList}}<br>
Line 11: Line 9:
&rarr; {{l/ver/clade|Sys\Data\Engine\aux\AdminRq\ToDbOper|EngDbTest}}<br>
&rarr; {{l/ver/clade|Sys\Data\Engine\aux\AdminRq\ToDbOper|EngDbTest}}<br>
&rarr; {{l/ver/clade|Sys\Data\Engine\aux\AdminRq\ToDbOper|EngDbUConf}}
&rarr; {{l/ver/clade|Sys\Data\Engine\aux\AdminRq\ToDbOper|EngDbUConf}}
|-
| colspan=3 align=center |


{| class="wikitable"
{{!-!}} '''Base'''* [c,i] || {{l/ver/clade/full|p=ferreteria|Sys\Data\Engine\aux\ActionRq|Admin}}
|-
{{!-!}} '''DbOper'''* [i] || {{l/ver/clade/full|p=ferreteria|Sys\Data\Engine|Ops}}
! colspan=2 | Clade Aliases
{{!-!}} '''QStr'''* [i]  || {{l/ver/clade/full|p=ferreteria|Data\Mem\QVar|Str}}
|-
! Alias || Clade
|-
| '''Base'''* [c,i] || {{l/ver/clade|Sys\Data\Engine\aux\ActionRq|Admin}}
|-
| '''DbOper'''* [i] || {{l/ver/clade|Sys\Data\Engine|Ops}}
|-
| '''QStr'''* [i]  || {{l/ver/clade|Data\Mem\QVar|Str}}


|}
}}
 
|}
==About==
==About==
* '''Purpose''': parent-class for {{l/ver/clade|Sys\Data\Engine\aux|ActionRq|Action Request}}s that require a {{l/ver/clade|Sys\Data\Engine|Ops|Database Operations}} object
* '''Purpose''': parent-class for {{l/ver/clade|Sys\Data\Engine\aux|ActionRq|Action Request}}s that require a {{l/ver/clade|Sys\Data\Engine|Ops|Database Operations}} object


The <code>caToDbOper</code> class needs to know how to find a {{l/ver/clade|Sys\Data\Engine|Ops|Database Operations}} object from a db name-slug, but can't know where that slug is specified. The <code>QDbConnSlug()</code> function, which returns the value/status of that parameter, is therefore <code>abstract</code>. The same is true of the Schema name-slug. It is up to descendant classes (generally found within application code) to define where those slugs can be found, and return a {{l/ver/clade|Data/Mem/QVar|Str|value/status string}} object for each.
The <code>caToDbOper</code> class needs to know how to find a {{l/ver/clade|Sys\Data\Engine|Ops|Database Operations}} object from a db name-slug, but can't know where that slug is specified. The <code>QDbConnSlug()</code> function, which returns the value/status of that parameter, is therefore <code>abstract</code>. The same is true of the Schema name-slug. It is up to descendant classes (generally found within application code) to define where those slugs can be found, and return a {{l/ver/clade|Data/Mem/QVar|Str|value/status string}} object for each.
* '''Parallel''': {{l/same|ToDbConn}}
==Code==
==Code==
''as of 2025-10-05''
''as of 2025-10-05''

Revision as of 14:17, 25 October 2025

clade: Sys\Data\Engine\aux\ActionRq\Admin\ToDbOper
Clade Family
Admin ToDbOper

EngDbExport
EngDbScList
EngDbSetup
EngDbTest
EngDbUConf

Base* [c,i]
Clade Aliases
Alias Clade
Subpages

About

The caToDbOper class needs to know how to find a Database Operations object from a db name-slug, but can't know where that slug is specified. The QDbConnSlug() function, which returns the value/status of that parameter, is therefore abstract. The same is true of the Schema name-slug. It is up to descendant classes (generally found within application code) to define where those slugs can be found, and return a value/status string object for each.

Code

as of 2025-10-05

interface iToDbOper extends BaseIface {
    #static function FromDbOper(DbOperIface $o) : self;
    // ERROR CODES
    const N_ERR_DB_DEFN = 1;
    const N_ERR_DB_SLUG = 2;
}
abstract class caToDbOper extends BaseClass implements iToDbOper {

    // ++ REGISTRY ++ //

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

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

    private $oDbOp = NULL;
    protected function QDbOper() : QDbOperIface {
        $qoDbOp = $this->FetchDBOper();
        $oItWent = $this->HowItWent();
        if ($qoDbOp->HasIt()) {
            #echo $qoDbOp->ReflectThis()->Report();
            $oDbOp = $qoDbOp->GetObj();
            $this->oDbOp = $oDbOp;
            $qoDbOp->SetIt($oDbOp);
            $oItWent->SetOkay(TRUE);
        } else {
            // the ops object was not retrieved
            $oItWent->SetOkay(FALSE);

            // get more details
            $qsDbSlug = $this->QDbConnSlug();
            if ($qsDbSlug->HasIt()) {
                #echo $qoDbOp->ReflectThis()->Report();
                $sSlug = $qsDbSlug->GetIt();
                $oItWent->AddMsgString(self::Screen()->ErrorIt("Internal issue while loading the '$sSlug' DB definition."));
                $oItWent->SetError(self::N_ERR_DB_DEFN);
            } else {
                $oItWent->AddMsgString(self::Screen()->ErrorIt('Internal issue accessing the DB slug.'));
                $oItWent->SetError(self::N_ERR_DB_SLUG);
            }
        }
        return $qoDbOp;
    }
    protected function DbOper() : QDbOperIface {
        $oDbOp = $this->oDbOp;
        if (is_null($oDbOp)) {
            $qoDbOp = $this->FetchDBOper();
        }
        return $oDbOp;
    }
    // ACTION: tries to retrieve the slug-requested DB from the db classifest
    protected function FetchDbOper() : QDbOperIface {
        $osDbSlug = $this->QDbConnSlug();
        #$osScSlug = $this->QSchemaSlug();
        #echo $oaData->ReflectThis()->Report();
        $doListFiles = FALSE;   // flip this on if the user needs it
        $qoDB = QDbOperClass::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();
                #echo $oDbConn->ReflectThis()->Report();
                $oDbOper = $oDbConn->OOper();
                $qoDB->SetIt($oDbOper);
                #$this->SetOkay(TRUE);
            }
        } else {
            #$this->SetOkay(FALSE);
        }
        return $qoDB;
    }
    abstract protected function QDbConnSlug() : QStrIface;
    abstract protected function QSchemaSlug() : QStrIface;

    // -- OBJECTS -- //
    // ++ OUTPUT ++ //

    public function ListHosts() : string {

        $oScrn = self::Screen();

        #$oaDBs = DbConnAdmin::Register();
        $oaDBs = $this->DbasesOArray();

        $nDBs = $oaDBs->Count();
        if ($nDBs > 0) {
            $oTable = $oScrn->NewTable();
            $sS = ($nDBs == 1) ? '' : 's';
            $sOut = $oScrn->InfoIt($nDBs)." available DB connection$sS:".CRLF;
            $oHdr = $oTable->RowFromData(['name','specs']);
            $oHdr->IsHeader(TRUE);
            $oaDBs->RewindMe();
            foreach ($oaDBs as $sKey => $oConn) {
                #echo "[$sKey] DB CLASS: ".get_class($oConn).CRLF;
                $arRow = [$sKey,$oConn->DescribeInline()];
                $oTable->RowFromData($arRow);
            }
            $sOut .= $oTable->Render();
        } else {
            $sOut = 'No database connections are defined yet.'.CRLF;
        }
        return $sOut;
    }

    // -- OUTPUT -- //
}