Ferreteria/v0.6/clade/Sys/Data/Engine/endpt/Client/MyMar/@fx/NewSchemaList/@versions

From Woozle Writes Code
< Ferreteria‎ | v0.6‎ | clade‎ | Sys‎ | Data‎ | Engine‎ | endpt/Client‎ | MyMar‎ | @fx/NewSchemaList
Jump to navigation Jump to search
Previous Version

2026-04-05

Same as 04/01... and some things will very likely need rearranging:

#
    protected function NewSchemaList() : SchemasIface {
        #$oStart = $this->OEngine()->OStarter();
        #$oStart->Open();
        #echo $oStart->ReflectThis()->Report();
        #$oSess = $this->OSession();
        #$oSess = $oStart->QOSession()->GetIt();
        $oSess = $this->OEngine()->OSession();

        /* 2026-04-03 This won't work anymore.
        $oCmdSess = $oSess->OCommand();
        $oCmdListen = new BufferClass;
        $oCmdSess->QOListener()->SetIt($oCmdListen);
        $oCmdErrors = new ScrnErrsClass; // stream for receiving error messages
        $oCmdSess->QOErrorBin()->SetIt($oCmdErrors);
        */

        #echo $oSess->ReflectThis()->Report();

        $oSyntax = $this->OSyntax();

        $oCmdThis = CommandClass::FromString($oSyntax->ListSchemas());

        $oSListen = new BufferClass;
        $oSess->QOStrmListener()->SetIt($oSListen);
        $oSErrors = new ScrnErrsClass; // stream for receiving error messages
        $oSess->QOStrmErrorBin()->SetIt($oSErrors);

        // This is if we want to use the Listener -- but actually, I think we want the Runner's Lecturer.
        UpdateClass::FromEngine($this->OEngine(),$oSListen);
        $oOpOpen = $oSess->Open();
        $oActCmd = $oSess->DoCommand($oCmdThis);

        $oOpRun = $oSess->DoInOutLoop();

        // 2026-03-03 Write handling of error messages later, if needed. (If we keep occasionally getting empty results, for example.)
        #$oMsgs = $this->MsgMatcher();

        $oActApp = $this->OpCommStatus();
        $oScrn = self::Screen();

        $oaSchemas = SchemasClass::AsNew();

        if ($oActCmd->GetOkay()) {

            $oOpData = $oSListen->PullBytes();
            if ($oOpData->GetOkay()) {
                $sNames = $oOpData->QData()->GetIt();
                #$this->AmHere('QData: '.$sNames);
                $arNames = explode("\n",trim($sNames)); // we might want to ensure that CRLF, CR, and LF all work as EOL.

                $sFirst = array_shift($arNames);
                #if ($sFirst == "Database") {
                    $oActApp->SetOkay(TRUE);
                    foreach ($arNames as $sName) {
                        $oSchema = $this->GetSchema($sName);
                        $oaSchemas->AddSchema($oSchema);
                    }
                /*
                } else {
                    $oActApp->SetOkay(FALSE);
                    // "Database" is the standard header for list of databases (schemas).
                    // If we don't see this, then something isn't right.
                    $sMsg = $oScrn->ErrorIt('Problem').": Something's not right with the db list. Here's what we got:".CRLF.$sNames;
                    $oActApp->AddMsgString($sMsg);
                }
                */
            } else {
                $this->AmHere('PullBytes() result:'.CRLF.$oOpData->VIEW_AsBlock());
            }
        } else {
            $this->AmHere('Command did not succeed');
            $sMsg = self::Screen()->ErrorIt('Problem').': the connection does not seem to be working.';
            $oActApp->SetOkay(FALSE);
            $oActApp->AddMsgString($sMsg);
        }
        #$oStart->Shut();
        // 2026-04-04 Should $oSess->Shut() be called here?

        return $oaSchemas;
    }

2026-04-01

I wanted to clean out all the debug code, but there's a lot of it and it makes me nervous to just delete it wholesale -- so I'm saving the complete function here, before removing anything, in case I need it again.

#
    protected function NewSchemaList() : SchemasIface {

        // ++ DEBUGGING

        /*
        #$cmdMain = 'mariadb -hlocalhost -uroot -pSum34thiIng';
        #$cmdMain = ['mysql', '--batch', '--raw', '--skip-pager','-uroot', '-pSum34thiIng'];
        $cmdMain = ['mariadb','--batch','--silent','--raw','--skip-pager','--unbuffered','-uroot', '-pSum34thiIng'];
        $sCmdSub = 'SHOW DATABASES';
        #$cmdMain = ['bash'];
        #$sCmdSub = 'ls -al';

        $aDefs = [
          0 => ['pipe', 'r'],  // STDIN
          1 => ['pipe', 'w'],  // STDOUT
          2 => ['pipe', 'w'],  // STDERR
          ];
        $rProc = proc_open($cmdMain,$aDefs,$aPipes);
        stream_set_blocking($aPipes[1], false);
        stream_set_blocking($aPipes[2], false);

        mysql_send($aPipes, $sCmdSub);
        list($out1, $err1) = mysql_read_response($rProc, $aPipes);

        // When done:
        fclose($aPipes[0]); // tell mysql no more commands

        // Drain remaining output
        $out_final = stream_get_contents($aPipes[1]);
        $err_final = stream_get_contents($aPipes[2]);

        fclose($aPipes[1]);
        fclose($aPipes[2]);

        $exit = proc_close($rProc);

        echo "OUT1:\n$out1\n";
        echo "ERR1:\n$err1\n";
        echo "OUTF:\n$out_final\n";
        echo "ERRF:\n$err_final\n";
        */

        // -- DEBUGGING


        #$qoStart = $this->QOStarter();
        $oSess = $this->OSession();
        #echo $oSess->ReflectThis()->Report(); // can we access the Session's Command object?
        $oCmdSess = $oSess->OCommand();
        $oCmdListen = new BufferClass;
        $oCmdSess->QOListener()->SetIt($oCmdListen);
        $oCmdErrors = new ScrnErrsClass; // stream for receiving error messages
        $oCmdSess->QOErrorBin()->SetIt($oCmdErrors);

        #$this->AmHere();

        $oSyntax = $this->OSyntax();

        $oCmdSub = CommandClass::FromString($oSyntax->ListSchemas());

        #$this->AmHereShort('$oCmdListen: '.$oCmdListen->VIEW_Inline());

        #echo $oCmd->ReflectThis()->Report();
        #$this->AmHereShort('SESS COMMAND: '.$oCmdSess->DEBUG_AsBlock());
        #$this->AmHereShort('SUB-COMMAND: '.$oCmdSub->DEBUG_AsBlock());

        // This is if we want to use the Listener -- but actually, I think we want the Runner's Lecturer.
        #$oCmdListen->QOUpdater()->SetIt(UpdateClass::FromEngine($this->OEngine(),$oCmdListen));
        UpdateClass::FromEngine($this->OEngine(),$oCmdListen);
        #$this->AmHere();
        $oOpOpen = $oSess->Open();
        $oActCmd = $oSess->SendCommand($oCmdSub);

        // ++ DEBUGGING

        /*
        #echo $oSess->ReflectThis()->Report(); // how do we get a stream to send to?

        $oSessRespond = $oSess->ORespond();
        $rSO = $oSessRespond->DEBUG_Resource();
        $oSessLecture = $oSess->OLecture();
        $rSI = $oSessLecture->DEBUG_Resource();
        $oSessErrors = $oSess->OErrsBin();
        $rSE = $oSessErrors->DEBUG_Resource();

        $this->AmHere();
        $nOk = fwrite($rSO,"SHOW SCHEMAS;\n");
        $this->AmHere('WRITTEN: '.(is_int($nOk) ? $nOk.' bytes' : 'NONE'));
        fflush($rSO);
        $this->AmHere();
        stream_set_blocking($rSI,FALSE);
        stream_set_blocking($rSE,FALSE);
        $sIn = stream_get_contents($rSI);
        $this->AmHere("RECEIVED: [$sIn]");
        $sIn = stream_get_contents($rSE);
        $this->AmHere("ERRORS: [$sIn]");

        #$oSessRespond->Open();
        #$this->AmHere('$oSessRespond before push: '.CRLF.$oSessRespond->DEBUG_AsBlock());
        #$oSessRespond->PushBytes("SHOW SCHEMAS;\n");
        #echo $oSessRespond->ReflectThis()->Report(); // where is VIEW_AsBlock() and why is it giving a different answer for bytes-pushed?
        #$this->AmHere('$oSessRespond after push: '.CRLF.$oSessRespond->DEBUG_AsBlock());
        #$oSessRespond->Shut();  // close to-process stream so process will respond
        #fclose($r);
        */

        /*
        $this->AmHere('$oSessLecture resource: ['.self::DiagnoseValue($r).'] eof?['.feof($r).']');
        #$oSessLecture->Open();
        $this->AmHere('$oSessLecture: '.CRLF.$oSessLecture->VIEW_AsBlock());
        #echo $oSessLecture->ReflectThis()->Report(); // how to pull bytes directly?
        $this->AmHere('READING from process lecture');
        $oOpData = $oSessLecture->PullBytes();
        $this->AmHere('DIRECT READ: '.$oOpData->VIEW_AsBlock());
        #$oSessLecture->Shut();
        */

        // -- DEBUGGING

        $oOpRun = $oSess->DoInOutLoop();

        // 2026-03-03 Write handling of error messages later, if needed. (If we keep occasionally getting empty results, for example.)
        #$oMsgs = $this->MsgMatcher();

        $oActApp = $this->OpCommStatus();
        $oScrn = self::Screen();

        $oaSchemas = SchemasClass::AsNew();

        if ($oActCmd->GetOkay()) {

            $oOpData = $oCmdListen->PullBytes();
            if ($oOpData->GetOkay()) {
                $sNames = $oOpData->QData()->GetIt();
                $arNames = explode("\n",trim($sNames)); // we might want to ensure that CRLF, CR, and LF all work as EOL.

                $sFirst = array_shift($arNames);
                if ($sFirst == "Database") {
                    $oActApp->SetOkay(TRUE);
                    foreach ($arNames as $sName) {
                        $oSchema = $this->GetSchema($sName);
                        $oaSchemas->AddSchema($oSchema);
                    }
                } else {
                    $oActApp->SetOkay(FALSE);
                    // "Database" is the standard header for list of databases (schemas).
                    // If we don't see this, then something isn't right.
                    $sMsg = $oScrn->ErrorIt('Problem').": Something's not right with the db list. Here's what we got:".CRLF.$sNames;
                    $oActApp->AddMsgString($sMsg);
                }
            } else {
                $this->AmHere('PullBytes() result:'.CRLF.$oOpData->VIEW_AsBlock());
            }
        } else {
            $this->AmHere('Command did not succeed');
            $sMsg = self::Screen()->ErrorIt('Problem').': the connection does not seem to be working.';
            $oActApp->SetOkay(FALSE);
            $oActApp->AddMsgString($sMsg);
            #echo '$oActCmd status: '.$oActCmd->VIEW_Inline().CRLF;
            #echo '$oActApp status: '.$oActApp->VIEW_Inline().CRLF;
        }

        return $oaSchemas;
    }