@@ -14,7 +14,7 @@ import { Tools } from './Tools';
1414import * as configVars from './configVars' ;
1515import { DebugConfiguration } from "./configuration/DebugConfiguration" ;
1616import { ConnectionManager } from './configuration/config/ConnectionManager' ;
17- import { CommandData , CommandResult , ConnectionData , IBMiMember , RemoteCommand , WrapResult } from './types' ;
17+ import { AspInfo , CommandData , CommandResult , ConnectionData , IBMiMember , RemoteCommand , WrapResult } from './types' ;
1818import { EventEmitter } from 'stream' ;
1919import { ConnectionConfig } from './configuration/config/types' ;
2020import { EditorPath } from '../typings' ;
@@ -97,12 +97,16 @@ export default class IBMi {
9797 currentConnectionName : string = `` ;
9898 private tempRemoteFiles : { [ name : string ] : string } = { } ;
9999 defaultUserLibraries : string [ ] = [ ] ;
100+
100101 /**
101102 * Used to store ASP numbers and their names
102103 * Their names usually maps up to a directory in
103104 * the root of the IFS, thus why we store it.
104105 */
105- aspInfo : { [ id : number ] : string } = { } ;
106+ private iAspInfo : AspInfo [ ] = [ ] ;
107+ private currentAsp : string | undefined ;
108+ private libraryAsps = new Map < string , number > ( ) ;
109+
106110 remoteFeatures : { [ name : string ] : string | undefined } ;
107111
108112 variantChars : {
@@ -728,20 +732,26 @@ export default class IBMi {
728732
729733 if ( this . sqlRunnerAvailable ( ) ) {
730734 // Check for ASP information?
731- if ( quickConnect ( ) && cachedServerSettings ?. aspInfo ) {
732- this . aspInfo = cachedServerSettings . aspInfo ;
735+ if ( quickConnect ( ) && cachedServerSettings ?. iAspInfo ) {
736+ this . iAspInfo = cachedServerSettings . iAspInfo ;
733737 } else {
734738 callbacks . progress ( {
735- message : `Checking for ASP information.`
739+ message : `Checking for iASP information.`
736740 } ) ;
737741
738742 //This is mostly a nice to have. We grab the ASP info so user's do
739743 //not have to provide the ASP in the settings.
740744 try {
741745 const resultSet = await this . runSQL ( `SELECT * FROM QSYS2.ASP_INFO` ) ;
742746 resultSet . forEach ( row => {
747+ // Does not ever include SYSBAS/SYSTEM, only iASPs
743748 if ( row . DEVICE_DESCRIPTION_NAME && row . DEVICE_DESCRIPTION_NAME && row . DEVICE_DESCRIPTION_NAME !== `null` ) {
744- this . aspInfo [ Number ( row . ASP_NUMBER ) ] = String ( row . DEVICE_DESCRIPTION_NAME ) ;
749+ this . iAspInfo . push ( {
750+ id : Number ( row . ASP_NUMBER ) ,
751+ name : String ( row . DEVICE_DESCRIPTION_NAME ) ,
752+ type : String ( row . ASP_TYPE ) ,
753+ rdbName : String ( row . RDB_NAME )
754+ } ) ;
745755 }
746756 } ) ;
747757 } catch ( e ) {
@@ -752,6 +762,12 @@ export default class IBMi {
752762 }
753763 }
754764
765+ callbacks . progress ( {
766+ message : `Fetching current iASP information.`
767+ } ) ;
768+
769+ this . currentAsp = await this . getUserProfileAsp ( ) ;
770+
755771 // Fetch conversion values?
756772 if ( quickConnect ( ) && cachedServerSettings ?. jobCcsid !== null && cachedServerSettings ?. userDefaultCCSID && cachedServerSettings ?. qccsid ) {
757773 this . qccsid = cachedServerSettings . qccsid ;
@@ -893,7 +909,7 @@ export default class IBMi {
893909
894910 IBMi . GlobalStorage . setServerSettingsCache ( this . currentConnectionName , {
895911 lastCheckedOnVersion : currentExtensionVersion ,
896- aspInfo : this . aspInfo ,
912+ iAspInfo : this . iAspInfo ,
897913 qccsid : this . qccsid ,
898914 jobCcsid : this . userJobCcsid ,
899915 remoteFeatures : this . remoteFeatures ,
@@ -1434,6 +1450,68 @@ export default class IBMi {
14341450 return this . remoteFeatures [ `startDebugService.sh` ] !== undefined ;
14351451 }
14361452
1453+ private async getUserProfileAsp ( ) : Promise < string | undefined > {
1454+ const [ currentRdb ] = await this . runSQL ( `values current_server` ) ;
1455+
1456+ if ( currentRdb ) {
1457+ const key = Object . keys ( currentRdb ) [ 0 ] ;
1458+ const rdbName = currentRdb [ key ] ;
1459+ const currentAsp = this . iAspInfo . find ( asp => asp . rdbName === rdbName ) ;
1460+
1461+ if ( currentAsp ) {
1462+ return currentAsp . name ;
1463+ }
1464+ }
1465+ }
1466+
1467+ getAllIAsps ( ) {
1468+ return this . iAspInfo ;
1469+ }
1470+
1471+ getIAspDetail ( by : string | number ) {
1472+ let asp : AspInfo | undefined ;
1473+ if ( typeof by === 'string' ) {
1474+ asp = this . iAspInfo . find ( asp => asp . name === by ) ;
1475+ } else {
1476+ asp = this . iAspInfo . find ( asp => asp . id === by ) ;
1477+ }
1478+
1479+ if ( asp ) {
1480+ return asp ;
1481+ }
1482+ }
1483+
1484+ getIAspName ( by : string | number ) : string | undefined {
1485+ return this . getIAspDetail ( by ) ?. name ;
1486+ }
1487+
1488+ getCurrentIAspName ( ) {
1489+ return this . currentAsp ;
1490+ }
1491+ async lookupLibraryIAsp ( library : string ) : Promise < string | undefined > {
1492+ let foundNumber = this . libraryAsps . get ( library ) ;
1493+
1494+ if ( ! foundNumber ) {
1495+ const [ row ] = await this . runSQL ( `SELECT IASP_NUMBER FROM TABLE(QSYS2.LIBRARY_INFO('${ this . sysNameInAmerican ( library ) } '))` ) ;
1496+ const iaspNumber = Number ( row ?. IASP_NUMBER ) ;
1497+ if ( iaspNumber >= 0 ) {
1498+ this . libraryAsps . set ( library , iaspNumber ) ;
1499+ foundNumber = iaspNumber ;
1500+ }
1501+ }
1502+
1503+ if ( foundNumber ) {
1504+ return this . getIAspName ( foundNumber ) ;
1505+ }
1506+ }
1507+
1508+ getLibraryIAsp ( library : string ) {
1509+ const found = this . libraryAsps . get ( library ) ;
1510+ if ( found && found >= 0 ) {
1511+ return this . getIAspName ( found ) ;
1512+ }
1513+ }
1514+
14371515 /**
14381516 * @deprecated Use {@link IBMiContent.uploadFiles} instead.
14391517 */
0 commit comments