Microsoft SQL Support
vicente
Joined: 2006-03-15
Posts: 23 |
![]() |
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? |
|
mindless
![]()
Joined: 2004-01-04
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?) |
|
Larry Menard
![]()
Joined: 2005-10-01
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. |
|
vicente
Joined: 2006-03-15
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 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. |
|
mindless
![]()
Joined: 2004-01-04
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.. |
|
vicente
Joined: 2006-03-15
Posts: 23 |
![]() |
in the db2 port notes there is a step as follows: in modules/core/classes/GalleryStorage.class case 'postgres': I cannot seem to find this, has this changed since the db2 port? Vince |
|
vicente
Joined: 2006-03-15
Posts: 23 |
![]() |
I found it in Gallery.class |
|
Larry Menard
![]()
Joined: 2005-10-01
Posts: 757 |
![]() |
Ah, I didn't realize this too had been moved after I implemented the DB2 change. |
|
vicente
Joined: 2006-03-15
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 |
|
Larry Menard
![]()
Joined: 2005-10-01
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'. lmenard@larryhome /cygdrive/c/temp/gallery2/modules/core/classes/GalleryStorage $ gmake 2>&1 | tee gmake.out perl ../../../../lib/tools/bin/extractClassXml.pl --dtd=../../../../lib/tools/dt d/GalleryClass2.0.dtd --quiet --out-dir=tmp/classxml ../*.class php -f ../../../../lib/tools/bin/generate-dbxml.php php -f ../../../../lib/tools/bin/generate-sql.php After this, you should have a new 'schema.tpl': lmenard@larryhome /cygdrive/c/temp/gallery2/modules/core/classes/GalleryStorage $ ls -l schema.tpl -rw-r--r-- 1 lmenard None 115269 Mar 22 09:24 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. |
|
vicente
Joined: 2006-03-15
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... |
|
doomdead
Joined: 2003-04-06
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) |
|
vicente
Joined: 2006-03-15
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? |
|
Larry Menard
![]()
Joined: 2005-10-01
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. |
|
vicente
Joined: 2006-03-15
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) 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 |
|
Larry Menard
![]()
Joined: 2005-10-01
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. |
|
vicente
Joined: 2006-03-15
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... |
|
Larry Menard
![]()
Joined: 2005-10-01
Posts: 757 |
![]() |
The last line in the trace very clearly says it was not succesful. Quote:
Error: Failure during install core module step I see one error in your trace... b>Warning</b>: mssql_query() [<a href='function.mssql-query'>function.mssql-query</a>]: message: Cannot insert the value NULL into column 'g_bits', table 'gallery3.dbo.g2_PermissionSetMap'; column does not allow nulls. INSERT fails. (severity 16) in <b>C:\Inetpub\wwwroot\gallerymssql\lib\adodb\drivers\adodb-mssql.inc.php</b> on line <b>690</b><br /> <br /> <b>Warning</b>: mssql_query() [<a href='function.mssql-query'>function.mssql-query</a>]: Query failed in <b>C:\Inetpub\wwwroot\gallerymssql\lib\adodb\drivers\adodb-mssql.inc.php</b> on line <b>690</b><br /> 515: The statement has been terminated.<br> It says "Warning", but I don't trust that. |
|
vicente
Joined: 2006-03-15
Posts: 23 |
![]() |
ok... I managed to get core modules to install succesfully and about 90% of the additional modules, but still have an Vince |
|
vicente
Joined: 2006-03-15
Posts: 23 |
![]() |
ok ... I figured there is "other" file needed to be deleted. I can now install all modules Configuration Error: Missing Theme If I try logon as admin I get the following Back to the Gallery There is no debug output... Any ideas? |
|
vicente
Joined: 2006-03-15
Posts: 23 |
![]() |
also... do you have a makefile that will call gmake for all the modules that need it...I noticed there are maybe my problem is being caused by a tpl file that I missed... Vince |
|
Larry Menard
![]()
Joined: 2005-10-01
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:
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. |
|
Larry Menard
![]()
Joined: 2005-10-01
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? |
|
vicente
Joined: 2006-03-15
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... |
|
vicente
Joined: 2006-03-15
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 but mssql gives the error The following sql works in mssql Is there a way to specify the GROUP BY clause in generate-sql? Vince |
|
Larry Menard
![]()
Joined: 2005-10-01
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. |
|
mindless
![]()
Joined: 2004-01-04
Posts: 8601 |
![]() |
The script that makes schema files for all modules: lib/tools/bin/rebuild-modules.pl |
|
vicente
Joined: 2006-03-15
Posts: 23 |
![]() |
where can I get more info on the structure of the arrays that are passed into |
|
Larry Menard
![]()
Joined: 2005-10-01
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. |
|
Larry Menard
![]()
Joined: 2005-10-01
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: $query = ' SELECT [GalleryAccessSubscriberMap::itemId], ' . $bitOr . ' FROM [GalleryAccessMap], [GalleryAccessSubscriberMap] WHERE [GalleryAccessSubscriberMap::itemId] IN (' . $itemIdMarkers . ') AND [GalleryAccessSubscriberMap::accessListId] = [GalleryAccessMap::accessListId] AND [GalleryAccessMap::userOrGroupId] IN (' . $entityIdMarkers . ') GROUP BY [GalleryAccessSubscriberMap::itemId] '; I think it would be safe to just add the required column(s) to the existing GROUP BY. GROUP BY [GalleryAccessSubscriberMap::itemId],[GalleryAccessMap::permission],[GalleryAccessSubscriberMap::itemId] Try it and see how it goes. Mindless (or any other lead developers), any concern with that change? |
|
mindless
![]()
Joined: 2004-01-04
Posts: 8601 |
![]() |
no, don't think that is right.. the error message was: BIT_OR is an aggregate function, we don't want permissions in the GROUP BY. |
|
Larry Menard
![]()
Joined: 2005-10-01
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. |
|
vicente
Joined: 2006-03-15
Posts: 23 |
![]() |
ok...great feedback... I also found the code in GalleryPermissionHelper_medium.class and tried the change and it worked, I am using sql servers bit or which is the | character The sql is ORing the permission values and not ORing them with itemid, but MS SQL is a bit strange with the 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 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 2006-03-26 12:31:48 [<no session id>] -------------------------------------------------------- 2006-03-26 12:31:48 [<no session id>] [1143365508] can't guarantee 120 -- extending! and thats it!! |
|
Larry Menard
![]()
Joined: 2005-10-01
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: G_ITEMID G_PERMISSIONS -------- -------------------------------- 1 00001110101001011000110101100111 1 00000001111100000101011111100000 1 10100000001000000000000000010000 2 00000001111011100000000001000000 2 01110000101000000000000000000101 2 00000000000000000000010000000000 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: G_ITEMID 2 -------- -------------------------------- 1 10101111111101011101111111110111 // <- BITOR of all G_PERMISSION values where G_ITEMID = "1" 2 01110001111011100000000001000101 // <- BITOR of all G_PERMISSION values where G_ITEMID = "2" 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: G_ITEMID 2 -------- -------------------------------- 1 11111111111111111101111111110111 // <- BITOR of *all* G_PERMISSION values 2 11111111111111111101111111110111 // <- BITOR of *all* G_PERMISSION values 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. |
|
Larry Menard
![]()
Joined: 2005-10-01
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.) |
|
Larry Menard
![]()
Joined: 2005-10-01
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. |
|
mindless
![]()
Joined: 2004-01-04
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". |
|
Larry Menard
![]()
Joined: 2005-10-01
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: SELECT g2_AccessSubscriberMap.g_itemId, MAX(G2_BIT_OR (g2_AccessSubscriberMap.g_itemId, g2_AccessMap.g_permission)) FROM g2_AccessMap, g2_AccessSubscriberMap WHERE g2_AccessSubscriberMap.g_itemId IN (7, 12) AND g2_AccessSubscriberMap.g_accessListId = g2_AccessMap.g_accessListId AND g2_AccessMap.g_userOrGroupId IN (5,4) GROUP BY g2_AccessSubscriberMap.g_itemId It returns: G_ITEMID 2 ----------- ------------------------------------------------------------------- 7 x'3030303030303030303030303030303030303030303030303030303030313131' 12 x'3030303030303030303030303030303030303030303030303130303030313131' 2 record(s) selected. (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. SQL0119N An expression starting with "G_PERMISSION" specified in a SELECT clause, HAVING clause, or ORDER BY clause is not specified in the GROUP BY clause or it is in a SELECT clause, HAVING clause, or ORDER BY clause with a column function and no GROUP BY clause is specified. SQLSTATE=42803 Vicente, try wrapping a MAX() around your BITOR? |
|
vicente
Joined: 2006-03-15
Posts: 23 |
![]() |
-I started the day by fixing the "hang error". It was a error on my part in the mssqlstorage.class file. I have spent the rest of the trying to figure out the Configuration Error: Missing Theme error. It should default to the default.theme. Also, now and then I get Any ideas? Vince |
|
Larry Menard
![]()
Joined: 2005-10-01
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? |
|
vicente
Joined: 2006-03-15
Posts: 23 |
![]() |
the matrix theme is installed. My matrix folder is 306 files, 137 folders (from CVS) at this point Im stumped... |
|
mindless
![]()
Joined: 2004-01-04
Posts: 8601 |
![]() |
the error page is modules/core/templates/ShowItemError.tpl |
|
mindless
![]()
Joined: 2004-01-04
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? |
|
Larry Menard
![]()
Joined: 2005-10-01
Posts: 757 |
![]() |
C:\MyServer\Gallery2\themes\matrix>dir /s | tail -n4 Total Files Listed: 99 File(s) 172,022 bytes 206 Dir(s) 2,283,507,712 bytes free 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. |
|
Larry Menard
![]()
Joined: 2005-10-01
Posts: 757 |
![]() |
Interesting... Windows' "find" completely fails to find this. |
|
vicente
Joined: 2006-03-15
Posts: 23 |
![]() |
I have attached the debug file... |
|
vicente
Joined: 2006-03-15
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. |
|
Larry Menard
![]()
Joined: 2005-10-01
Posts: 757 |
![]() |
Mindless may want to review your changes first. Wait for his advice. |
|
mindless
![]()
Joined: 2004-01-04
Posts: 8601 |
![]() |
oh, that debug output never loads default.theme to commit some code, post new files+diffs here.. I can review and commit. |
|
mindless
![]()
Joined: 2004-01-04
Posts: 8601 |
![]() |
FYI, I have just upgraded CVS to use ADODB 4.80 and included the mssql files. |
|
vicente
Joined: 2006-03-15
Posts: 23 |
![]() |
I need to find out how to create diff files in eclipse, |
|