I want to develop a Microsoft SQL Server driver for Gallery. I see that there is an xsl file for each db gallery supports and a class file. Where can I get the source for this class file? I looked in cvs but cannot seem to find the source, only the class file. Can someone give me an idea of the layout of the xsl file? Also will I have to change/create any other files?
If someone with knowledge of the procedure to do a port of an existing driver can give me a step by step guide, I will write the code and get it done.
Posts: 8601
great! best of luck on this project, we'll gladly provide guidance.
this isn't java; *.class files in G2 are source files, just open it up
another thing you'll need to edit is lib/tools/bin/generate-sql.php (I don't think there are xsl files anymore.. are you looking at current CVS?)
Posts: 757
Hi, Vicente.
As I mentioned in response to your e-mail, I would suggest you look at the first few appends in the forum thread for the DB2 support (http://gallery.menalto.com/node/37648). The process will probably be much the same for SQL Server as it was with DB2.
Posts: 23
Hello
Thanks for the responses. I checked out the postings for the db2 port and they have helped.
I’ve got eclipse running with the php plugin and got all the code from CVS.
I’ve added the necessary code to generate-sql.php for mssql. I can compile it and can see the generated sql in schema.tpl
How does gallery 2 use this schema.tpl when running the sql against the db? How does it resolve dependencies in the file, I see that the sql is not ordered by dependency? E.g. an alter table exists for a table before the create table sql.
I’ve created a MsSqlStorage class and have modified it. I just need to understand what the following functions are used for
encodeBlob
decodeBlob
_getOptimizeStatement
convertIntToBits
convertBitsToInt
If I know what they are used for, I can check if they are necessary for MS SQL.
Once I’ve done those functions, I can start testing.
Posts: 8601
Wow, great progress already!
The schema.tpl file contains all new install and upgrade sql for all DBs.. the comments in the file are separators. Anything with # {tablename} is used for installing the module; lines with # A_{tablename}_{version} are used only for the appropriate upgrades.
Check the phpdoc in GalleryStorage.class for a brief description of each of those functions.. also look at the other DB classes for examples. Ask again if there are still questions..
Posts: 23
in the db2 port notes there is a step as follows:
in modules/core/classes/GalleryStorage.class
add after
case 'postgres':
case 'postgres7':
GalleryCoreApi::relativeRequireOnce(
'modules/core/classes' . $base . 'DatabaseStorage/PostgreSqlDatabaseStorage.class');
$this->_impl = new PostgreSqlDatabaseStorage($config);
break;
I cannot seem to find this, has this changed since the db2 port?
Vince
Posts: 23
I found it in Gallery.class
Posts: 757
Ah, I didn't realize this too had been moved after I implemented the DB2 change.
Posts: 23
Hello
I need to know what to do now that the changes are complete; I have never done php development before, so please bear with me. Do I need to compile the code, or do I just copy it to my virtual directory on the web server and start testing it?
Thanks
Vince
Posts: 757
Hi Vince.
The only thing you need to 'build' is the 'gallery2/modules/core/classes/GalleryStorage/schema.tpl' file, which will contain the generated SQL based on your other changes.
To build this file, go to 'gallery2/modules/core/classes/GalleryStorage' and run 'gmake'.
After this, you should have a new 'schema.tpl':
And it should contain a section for your MS SQL. (Look for '##', that's how the db platform sections are delimited.)
Then, just move your changed files into the 'gallery2' tree on your server, and fire up the installer by pointing your browser to 'http://localhost/gallery2/install/index.php' and see how it goes.
Edit: I hope you have a Cygwin environment on your Windows system. If not, you'll need it for doing this build.
Posts: 23
thanks
Im running SUSE Linux in a virtual machine with samba, on my windows machine. I have compiled schema.tpl. I have gallery running on my windows machine, so I will use that to start testing.
thanks for the help...
Posts: 174
this is GREAT. ive been waiting for sql support. I'd be more than happy to help test it. (hopefully we can move the gallery data from mysql to mssql without any problems)
Posts: 23
Hello
I have started testing, after the Database Setup Step of the installer I get the successful page, but the db only has 2 tables, I removed them and tried again but now no tables are created.
any ideas?
Posts: 757
I'm not 100% sure, but I think that's normal. The Database Setup Step only creates a couple of test tables, just as a 'sanity check'. The majority of the tables and other objects are created later during the Core Module Install step.
Posts: 23
you are right, when I get to the install core modules step the 2 tables mentioned are created.
the error I get now is as follows
Error (ERROR_STORAGE_FAILURE)
in modules\core\classes\GalleryStorage.class at line 476 (GalleryCoreApi::error)
in modules\core\classes\Gallery.class at line 223 (GalleryStorage::search)
in modules\core\classes\helpers\GalleryPluginHelper_simple.class at line 519 (Gallery::search)
in modules\core\classes\helpers\GalleryPluginHelper_simple.class at line 391 (GalleryPluginHelper_simple::fetchPluginList)
in modules\core\classes\GalleryCoreApi.class at line 292 (GalleryPluginHelper_simple::fetchPluginStatus)
in modules\core\classes\GalleryPlugin.class at line 182 (GalleryCoreApi::fetchPluginStatus)
in modules\core\classes\GalleryModule.class at line 343 (GalleryPlugin::activate)
in install\steps\InstallCoreModuleStep.class at line 146 (GalleryModule::activate)
in install\index.php at line 201 (InstallCoreModuleStep::processRequest)
is there a log file or something with a more detailed error message, also do you know if it is possible to debug the php code with the php eclipse module with php running in IIS?
Vince
Posts: 757
Yeah, now you're getting to the fun part.
After the 'gallery2/config.php' file is created in Step 7, edit that file and enable debugging by changing line:
$gallery->setDebug(false);
to
$gallery->setDebug('buffered');
(Note that this file is recreated everytime you run Step 7, so you might have to re-enable debugging whenever you run Step 7.)
When debugging is enabled, look in your g2data directory for a file called 'install_*'. In that file, look for a few lines of version information being dumped. Ignore everything up to that point... the error you're looking for is somewhere below that.
Happy hunting.
Posts: 23
thanks
after fixing a few problems in the generate-sql file I now have 40 tables generated before the error
attached is the file, it seems to indicate that it was succesful, but I still get the error message...
Posts: 757
The last line in the trace very clearly says it was not succesful.
I see one error in your trace...
It says "Warning", but I don't trust that.
Posts: 23
ok...
I managed to get core modules to install succesfully and about 90% of the additional modules, but still have an
error, when going to the main page. I think I found the problem but now when I run the install again I get
an error on the database storage step. Before restarting the installation I deleted all the tables and all
files in the data directory, it seems as if gallery is trying to upgrade rather than do a fresh install, is
there a cache directory or file I need to delete to get gallery to do a fresh install...
Vince
Posts: 23
ok ... I figured there is "other" file needed to be deleted. I can now install all modules
succesfully but when I go to the main page I get the following...
Configuration Error: Missing Theme
Missing Theme
This album is configured to use the theme, but it is either inactive, not installed, or incompatible. To fix this problem you can login as a site administrator and then install or activate this theme or select another default theme
If I try logon as admin I get the following
Database Error
An error has occurred while interacting with the database.
Back to the Gallery
There is no debug output...
Any ideas?
Posts: 23
also...
do you have a makefile that will call gmake for all the modules that need it...I noticed there are
a few that need a schema.tpl, this will save me time, instead of me having to do each one manually...
maybe my problem is being caused by a tpl file that I missed...
Vince
Posts: 757
> existing database
In Installer Step 5 (Database Setup), if Gallery detects that there is an existing set of tables, there should be a button that gives you the option to remove and recreate those database objects. I forget the actual wording of this button, but the code that it fires is in the "GalleryStorage/mssqlDatabase.class" file you created, in a function called "cleanStore()". To be honest, that's the one thing i haven't tested really well yet in DB2.
It's very important that the database remains in sync with the contents of the g2data directory. I created a "recreate_db.bat" file that drops and recreates the database, and removes and recreates an empty "g2data". Before starting any Install, I run that script.
> Missing theme
Not sure how much I can help with this specific problem, but here's some general guidance based on my own experience:
1) Review the "install*.log" file to make sure there are no errors that were missed. If debug was not enabled, wipe the db and "g2data", re-run the Install with debug enabled.
2) You can enable debugging at any time, not just during the Install. For example, if you're having difficulty bringing up the main "gallery2/index.php" page, enable debugging and try it. You should see a lot of debug info. Note that the debug info is visible in your browser, it is not sent to a file. Again, there should be no errors in this debug output.
Note: When you enable debugging for runtime (non-Install) activity, it opens a separate browser running something called Smarty. I find it to be more annoying than useful. If you close that window, it just keeps coming back every time you refresh. So rather than close it, I minimize it, so at least it stays out of my way.
3) Look at the stack trace, and don't be afraid to put your own debug code into the source at those locations. For example, here's one I'm currently using:
printf("<br><br>In GalleryStorageExtras::_executeSql(), \$buffer = \"$buffer\".\n<br>");
4) When looking at the source code, watch for methods like "$this->_gs->_traceStart();" and "$this->_gs->_traceStop();" enclosing some execution statement. In non-Install cases, they have the effect of suppressing errors. You might find it helpful to temporarily comment them out.
Posts: 757
> makefile for modules
I'm afraid I have no idea why you'd need to do that. I never found any modules that needed any kind of 'build'... they all worked for me as-is.
Can you give me an example of such a module, and where is it looking for a 'schema.tpl' that does not exist?
Posts: 23
\gallery2\modules\comment\classes\GalleryStorage
has a tpl file, after I run gmake it has an entry for mssql
thanks for the other info, I will keep at it...
Posts: 23
ok... found the problem
gallery is generating sql like this
SELECT g2_AccessSubscriberMap.g_itemId, g2_AccessMap.g_permission | g2_AccessSubscriberMap.g_itemId
FROM g2_AccessMap, g2_AccessSubscriberMap
WHERE g2_AccessSubscriberMap.g_itemId IN (7)
AND g2_AccessSubscriberMap.g_accessListId = g2_AccessMap.g_accessListId
AND g2_AccessMap.g_userOrGroupId IN (5,4)
GROUP BY g2_AccessSubscriberMap.g_itemId
but mssql gives the error
Server: Msg 8120, Level 16, State 1, Line 1
Column 'g2_AccessMap.g_permission' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
The following sql works in mssql
SELECT g2_AccessSubscriberMap.g_itemId, g2_AccessMap.g_permission | g2_AccessSubscriberMap.g_itemId
FROM g2_AccessMap, g2_AccessSubscriberMap
WHERE g2_AccessSubscriberMap.g_itemId IN (7)
AND g2_AccessSubscriberMap.g_accessListId = g2_AccessMap.g_accessListId
AND g2_AccessMap.g_userOrGroupId IN (5,4)
GROUP BY g2_AccessSubscriberMap.g_itemId,g2_AccessMap.g_permission,g2_AccessSubscriberMap.g_itemId
Is there a way to specify the GROUP BY clause in generate-sql?
Vince
Posts: 757
> tpl file
Hmm, I wonder if that's because you're using code that was pulled directly from cvs, as opposed to from a nightly build? In my case (DB2), Valiant was checking in my changes frequently, so by the time I got to the additional modules, the base DB2 support was already there. Once your base changes go into cvs, you shouldn't have to do builds anywhere unless you change your SQL source.
> GROUP BY
See function getFunctionSql() in your "GalleryStorage/mssqlStorage.class". It is basically yours to do with as you please, though the lead developers are somewhat picky about what they allow for performance reasons. I think I had this same problem in DB2, so check out the getFunctionSql() in "GalleryStorage/Db2Storage.class".
You should also be able to modify the "MsSqlGenerator" block of code in "generate-sql.php" without impacting anyone else.
There is also SQL in "moodules/core/classes/helpers/*.class", but those are shared files, so changing those is not done easily.
Posts: 8601
The script that makes schema files for all modules: lib/tools/bin/rebuild-modules.pl
Posts: 23
where can I get more info on the structure of the arrays that are passed into
getfunctionsql() and generate-sql.php? None of the existing code generates the GROUP BY part of the
sql. I would imagine that the sql mentioned above is generated on the fly by gallery or is this
sql pre-generated and if so where is it?
Posts: 757
Could you please post the stack trace from the error, and I'll see if I can figure out where the GROUP BY is being added.
Generally speaking, to find out the contents of an array, I var_dump() it. Not the easiest thing to read, but it works.
Posts: 757
Never mind the stack trace, using 'grep' commands I was able to find the code that I think is stopping you. It's in "GalleryPermissionHelper_Medium.class", function "fetchPermissionsForItems()".
The GROUP BY clause *is* there, so I don't understand what you mean by "None of the existing code generates the GROUP BY part of the sql". Here's the code:
I think it would be safe to just add the required column(s) to the existing GROUP BY.
Try it and see how it goes.
Mindless (or any other lead developers), any concern with that change?
Posts: 8601
no, don't think that is right.. the error message was:
Column 'g2_AccessMap.g_permission' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
BIT_OR is an aggregate function, we don't want permissions in the GROUP BY.
so the problem is in the getFunctionSql generating the BIT_OR sql above.. it should OR'ing together all permissions values (aggregate), not OR'ing permissions with itemId.
Posts: 757
Ah, I'll bet Vicente copied the "Db2Storage.class" file. (In DB2, the 'G2_BIT_OR' aggregate function requires both columns to be passed into it. Chances are MS SQL's BIT_OR does not.)
Vicente, try copying a "case 'BIT_OR':" block from another database, e.g. PostGreSql.
Posts: 23
ok...great feedback...
I also found the code in GalleryPermissionHelper_medium.class and tried the change and it worked,
I still get the missing theme message but now I can log on as admin and browse through all admin menus with
no errors.
I am using sql servers bit or which is the | character
case 'BIT_OR':
$args = str_replace('?', '?', $args);
$sql = $args[0] . ' | ' . $args[1];
break;
The sql is ORing the permission values and not ORing them with itemid, but MS SQL is a bit strange with the
GROUP BY clause, it seems to want to have all items in the select list in the GROUP BY clause irrespective
of whether they are being ORed
so, the status is as follows
I was able to install successfully but when I went to the main page I got the following error
Configuration Error: Missing Theme
Missing Theme
This album is configured to use the theme, but it is either inactive, not installed, or incompatible. To fix this problem you can login as a site administrator and then install or activate this theme or select another default theme
I can now log in as admin. The theme seems to be active, so Im not sure what is causing the missing theme problem.
Also now I have a new problem, suddenly when I try to re-install, I get to the core install step and it
just seems to hang there, the install*.log file has the following
2006-03-26 12:31:48 [<no session id>]
--------------------------------------------------------
Prepare installation of the core module
--------------------------------------------------------
2006-03-26 12:31:48 [<no session id>] [1143365508] can't guarantee 120 -- extending!
2006-03-26 12:31:48 [<no session id>] Init first pass
2006-03-26 12:31:48 [<no session id>] file_exists(C:\Inetpub\wwwroot\gallerymssql\modules\core\classes\helpers/../../../../config.php)
2006-03-26 12:31:48 [<no session id>] file_exists(C:\Inetpub\wwwroot\gallerymssql\modules\core\classes\helpers/../../../../plugins/index.modules)
and thats it!!
Posts: 757
I think you have at least two separate issues here... the BIT_OR and the GROUP BY.
BIT_OR:
The additional passing of G_ITEMID into the BIT_OR is probably very specific to DB2. For now, forget you ever saw that. I suspect you don't need it.
The purpose of this BIT_OR is not to compare two columns. It is supposed to take the set of returned G_PERMISSIONS values and do bitwise ORing of those values against each other, then return the final BIT_ORed value.
For example, if the result set that satisfies the WHERE clause is:
Then what the query is supposed to do is return the BITOR of all the permissions for G_ITEMID "1", then the BITOR of all the permissions for G_ITEMID "2", etc. So, it should return:
DB2 unfortunately does not have built-in BIT functions, so I had to write my own (using a sample from the IBM DeveloperWorks site), but also unfortunately, aggregation using DB2 User-Defined Functions (UDFs) like that do not honour the GROUP BY clause in the original SQL, so the UDF needs to also know the G_ITEMID value for each row in order to do its own grouping. Otherwise it would just BITOR the entire set of G_PERMISSIONS values regardless of the G_ITEMID values. In the case of the above example, that would be:
GROUP BY:
So we might still need to add those columns to the GROUP BY clause from what I can see. It's Mindless that you need to convince.
Posts: 757
As for the missing theme, I don't know offhand how to debug that, it might even be related to the BIT_ORing for all I know. But here's what I would suggest.
I would suggest that maybe it would be a good idea to get your current changes checked into CVS. That way, you can use nightly build snapshots (which are usually known to be good) instead of relying on an old extract from CVS (which I think you are doing).
Unfortunately, this is not a good time to do so, because the release of v2.1 is so imminent. But as soon as v2.1 is released, I would suggest getting your changes checked in. (The MS SQL support can be marked "In Development" or something in the Installer.)
Posts: 757
Sorry for the multiple postings, I keep noticing things I haven't addressed yet.
For the hang... do you really mean "hang", or do you mean "exit"?
I've noticed that when I have a syntax error in a class file, the error might never be evident in the browser or the log file. Sometimes it just exits with no error msg.
Posts: 8601
if you'd like to post what you have so far we can get it into CVS.. 2.1 was released a few days ago.
if you need permissions in the group by clause then I don't understand mssql syntax at all. group by itemId means larry's example above would form 2 groups (as there are 2 different itemIds) and each group would aggregate 3 permission values. if you add permission in the group by, every database i know of would then return 6 different groups in this example, as every pair of itemId,permission is different.. only rows with the same itemId AND permission value would be "grouped".
Posts: 757
I should also have mentioned... in DB2 I also wrap a MAX() around the BIT_OR, so it doesn't actually print the intermediate results, only the max. My exact query is:
It returns:
(Don't get hung up on the hex representation... that's just DB2's way of saying it is FOR BIT DATA.)
When I remove the MAX(), I get the same error as Vicente.
Vicente, try wrapping a MAX() around your BITOR?
Posts: 23
-I started the day by fixing the "hang error". It was a error on my part in the mssqlstorage.class file.
-Using MAX() around the BITOR did work, thanks Larry.
I have spent the rest of the trying to figure out the
Configuration Error: Missing Theme
Missing Theme
This album is configured to use the theme, but it is either inactive, not installed, or incompatible. To fix this problem you can login as a site administrator and then install or activate this theme or select another default theme.
error. It should default to the default.theme.
My db does have a entry for default.theme, and it is even in the cache file in the data directory.
Does anyone have any idea of why this could be happenning, I have gone through the GalleryTheme.class
and put in printf statements, but cannot seem to figure out the problem.
Also, now and then I get
Notice: unserialize() [function.unserialize]: Error at offset 121 of 255 bytes in C:\Inetpub\wwwroot\gallerymssql2\modules\core\classes\GallerySession.class on line 935
Any ideas?
Vince
Posts: 757
Sorry, I have no idea why you're getting the "Missing Theme" error. I can't even find string "Missing Theme" in my entire Gallery2 tree, nor can I find any occurrence of "Missing" that looks like it might be followed by a variable that could be "Theme".
In "Site Admin -> Themes -> All Themes", what themes are installed (indicated by green circle)? On my system, "Matrix" is the only one installed, and it is therefore the default theme. Do you actually have a complete "gallery2/themes/matrix" directory? Mine is 99 files (172,022 bytes), in 206 directories.
I don't know anything about the session suport either. What is the value of $pSession[5] at that point when it fails?
Posts: 23
the matrix theme is installed. My matrix folder is 306 files, 137 folders (from CVS)
at this point Im stumped...
Posts: 8601
the error page is modules/core/templates/ShowItemError.tpl
Posts: 8601
it seems likely that getPluginParameter for default.theme is not returning a value.. can you add debug output to confirm this, any maybe dig into where it goes wrong?
Posts: 757
If your matrix directory is 306 files then something is obviously very different between your setup and mine.
I still suggest checking your changes into CVS. That way your code is sure to go through a complete build process, and also then our two environments would be more comparable.
Posts: 757
Interesting... Windows' "find" completely fails to find this.
Posts: 23
I have attached the debug file...
Posts: 23
In order to commit my changes, do I commit them to the head branch? This is where I got them (the original files) from.
Posts: 757
Mindless may want to review your changes first. Wait for his advice.
Posts: 8601
oh, that debug output never loads default.theme
in loads the root album (entity 7 I think) and thinks it has a particular theme.. ie, getTheme doesn't return an empty value so it doesn't load default.theme. check what value is in the db for this album, and in 7.inc!
to commit some code, post new files+diffs here.. I can review and commit.
Posts: 8601
FYI, I have just upgraded CVS to use ADODB 4.80 and included the mssql files.
Posts: 23
I need to find out how to create diff files in eclipse,
in the mean time I have atached a zip file with the files I added or changed.
Please note that I changed generate-sql file to only generate mysql and mssql while I was testing.