DBD-MaxDB

 view release on metacpan or  search on metacpan

MaxDB.xs  view on Meta::CPAN

#endif

/*
 * will return a structure like this or undef
 *
 * ref-+->progdir
 *     |
 *     +->datadir
 *     |
 *     +->user
 *     |
 *     +->group
 *     |
 *     +->database-+->SID0-+->dbname
 *                 |       |
 *                 |       +->dbowner
 *                 |       |
 *                 |       +->dbswdir
 *                 |
 *                 +->SID1-+->dbname
 *                 |       |
 *                 |       +->dbowner
 *                 |       |
 *                 |       +->dbswdir
 *                ...
 *
 * expects one parameter,
 * this is the name of the database we are looking for
 *
 * if no parameter is given,
 * it will look for all know database instances
 */

DBISTATE_DECLARE;

/*
* The source code of the package BD::MaxDB::util is taken from
* MaxDB's installation tool sdbinst. 
*
* :install56\perl\sdbrun\InstInfo.xs
*
* Thanks to ChristophB
*/


MODULE = DBD::MaxDB    PACKAGE = DBD::MaxDB::InstInfo

PROTOTYPES: DISABLE

void
new (...)
PREINIT:
	char *dbname;
	info_t *info;
	info_t *curr0;
	info_t *curr1;
	HV *hv0;
	HV *hv1;
	HV *hv2;
	SV *rv;
PPCODE:
	if (items >= 2)
		XSRETURN_UNDEF;

	dbname = 0;
	if (items == 1 && SvPOKp (ST(0)))
		dbname = (char *) SvPV (ST(0), PL_na);		

	info = get_instinfo (dbname);
	if (info == 0)
		XSRETURN_UNDEF;

	hv0 = newHV ();
	hv1 = 0;

	for (curr0 = info; curr0 != 0; curr0 = curr0->next) {
		if (curr0->key == 0)
			continue;

		if (strcmp (curr0->key, "db") == 0) {
			if (curr0->val == 0)
				continue;

			if (hv1 == 0)
				hv1 = newHV ();

			hv2 = newHV ();
			for (curr1 = (info_t *)(curr0->val); curr1 != 0; curr1 = curr1->next) {
				if (curr1->key == 0)
					continue;

				if (strcmp (curr1->key, "dbname") == 0) {
				  New (101, dbname, strlen (curr1->val) + 1, char); 

					if (dbname == 0)
						break;

					strcpy (dbname, curr1->val);
				}

				if (curr1->val == 0) {
					hv_store (
					hv2, curr1->key, strlen (curr1->key),
					newSVpv ("", 0), 0);
					continue;
				}

				if (strcmp (curr1->key, "dbswdir") == 0 ||
				    strcmp (curr1->key, "paramfile") == 0) {
					char *ptr;

					for (ptr = curr1->val; *ptr != 0; ptr++)
						if (*ptr == '\\')
							*ptr = '/';
				}

				hv_store (
				hv2, curr1->key, strlen (curr1->key),
				newSVpv (curr1->val, strlen (curr1->val)), 0);
			}



( run in 1.851 second using v1.01-cache-2.11-cpan-71847e10f99 )