Custom Libraries & Macro

i have a working code and it worked well when i run in AppInit event

sc_select(rs, “SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = ‘my_DB’ AND TABLE_NAME = ‘my_TABLE’;”);
if ({rs} === false) {
echo “Access error. Message =”. {rs_erro};
} else {
while (!$rs->EOF) {
echo $rs->fields[0] . “<br>”;
$rs->MoveNext();
}
$rs->Close();
}

But when i copy and pasted it into my custom libary files, the application return a blank page.
Is it true that macro can never be call in custom library?

Thanks for the clarifications

[QUOTE=weilies;27857]i have a working code and it worked well when i run in AppInit event

But when i copy and pasted it into my custom libary files, the application return a blank page.
Is it true that macro can never be call in custom library?

Thanks for the clarifications[/QUOTE]

No, you can use macro’s, we do it all the time. But the same rules for the macro’s apply when you call them from an event. In your screenshot there’s a syntax error as there’s a {} mismatch, but that can be a copy error. Useually the problem might be that you haven’t changed your code into a procedure/function or that you have a ; behind the function declaration.

hi Albert, i tried a few times, the same code block below executed in AppInit event and it’s working fine but when i cut & paste it into a custom library class, it will return me a blank screen.

here is the code block. No typo error

sc_select(rs, " SELECT COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = ‘astudion_virtualdesk’
AND TABLE_NAME = ‘country’;");

	if ({rs} === false) {
		echo "Access error. Message =". {rs_erro};
	} else {
		while (!$rs-&gt;EOF) {
			echo $rs-&gt;fields[0] . "&lt;br&gt;";
			$rs-&gt;MoveNext();
		} 
		$rs-&gt;Close();

You have to put this routine in a function and call the function. So I can’t tell regarding this code-snippet. But there’s something wrong in the generated code so you should look into the generated code to see what’s going on.

here the errors i got from hosting
[03-Oct-2014 03:35:14 America/Denver] PHP Fatal error: Call to undefined function sc_select() in /home4/astudion/public_html/sc.astudion.com/sc8/app/VirtualDesk/PersonPersonality/ExSQL.php on line 33

what i understand here is sc simply cant recognize the sc func if i put it in a class

[QUOTE=weilies;27873]here the errors i got from hosting
[03-Oct-2014 03:35:14 America/Denver] PHP Fatal error: Call to undefined function sc_select() in /home4/astudion/public_html/sc.astudion.com/sc8/app/VirtualDesk/PersonPersonality/ExSQL.php on line 33

what i understand here is sc simply cant recognize the sc func if i put it in a class[/QUOTE]

I don’t know, I use the library for storing functions and they contain loads of sc_ functions and there are no issues. For classes I don’t know.

maybe a silly question - but you have in Programming | Libraries - ticked the library in question in the app in question?

Yup, at first I thought I was as silly as that… but I checked :slight_smile:

hi Albert,

The same code i executed in onApplicationInit, no error.
But when i move it to a PHP function (as attched image), it throws me error

i wonder how u able to run it without error… could it because you using SC7?

macro error.jpg

hi Albert,

i managed to found ur old post
http://www.scriptcase.net/forum/archive/index.php/t-3310.html

looks like it’s a known bug and does they resolved it already?
not to say sc_select, it doesn’t work even i try call sc_alert in my custom library

having the macro in function worked. But it’s only within the app itself, i would need my method to be re-usable, so i rather put in libraries.

Plz let me know if SC team has already resolved the bug.

Thanks

If you look at my code there’s a invalid ‘;’ at the end of the function name. Removing it solved my issues. But look also at the scope of the macro, as this is vital. You can put anything in your library, but it depends on the moment where you call it if the macro can be found.

hi, i have composed the step-by-step with link below
https://docs.google.com/document/d/1bHC5vSJ5rjkewV4M4IylVCcZStDbADkf9TqQAeWm9u0/edit?usp=sharing

plz tell me if i have any missing steps which cause the macro failed in library :slight_smile:

Thanks in million

I don’t know, appearantly you can’t use classes. I never do.

The other thing maybe to try is the:

sc_include(xxx.php);

Add that in the onApplicationInit event of the app that calls that library (library still needs to be checked in Programming | Libraries.

hi adz1111,

It doesn’t work with sc_include :slight_smile:
But nice try.

Thanks

Hi weilies, I have the same problem, have you found a solution?
Thanks

Cannot use macros in classes within libraries, because of the nature of how the macros translate.

“$this” is expected to be a particular object when a macro is called.
When you create a class, you change the definition of “$this”.

Look at the code that macros generate and it will make sense.

Dave

Thank you Dave.