[solved] mysql: copy value from column to column and perform string operation
Posted: Sat Jun 13, 2009 2:11 pm
Hi there,
I am currently working on a kind of CMSMS experiment. For this I have imported some tables of data (own data structure, containing third party content). For simplification the table layout is:
ID: Integer (e.g. "12345")
Name: varchar(80) (e.g. "Some Text Entry")
Summary: text (e.g. "The summary of the topc")
To acccess the data, I want to use pretty URLs like: /page-alias/some-text-entry/
So I plan to use a rewrite rule like this:
RewriteCond %{REQUEST_URI} ^/page-alias/
RewriteRule ^([^/]*)/([^/]*) cmsms/index.php?page=page-alias&item-alias=$2 [QSA,L]
With smarty I capture the get value, pass it on to a plug-in or UDT and check the DB for the corresponding element. Then I can output the other item data.
The URL stuff works without problem. DB import was no problem and using the url to query the data also works (I manually edited some fields.
To problem comes, when I want to find the entry in the DB. Using the regular Name-field doesn't really work. "Some Text Entry" and "some-text-entry" do not match for obvious reason.
I can not just remove the "-" in the item-alias and uppercase the single words first letter to match, as the Name from the DB may contain special characters and such.
I can generate a nice alias from the original name by replacing specials characters and spaces and such with hyphens or ascii equivalents and lowercase the data. it basically does the same as CMSMS when auto creating a page alias.
So I got the single bits working nice but stuck at putting them all together. Probably this is more a mysql question than directly CMSMS related, but probably someone of you knows a quick way
I see these options:
A) Either I transform the Name with mysql-query and then compare it to the item-alias recieved, but then I need to transform a lot of entries and thus might generate a lot of CPU load for each query. Additionally, I can not index the item-aliases in the DB as they are generated on request.
B) I could create a new column named alias. Then I run a mysql query, that reads column name, does string operation and saves the result in the column alias. This would only have to be done once or each time the DB get's updated and is pure mysql.
C) I create the extra column and then run a PHP script that goes column by column and copy saves the text. This would also only be an operation that is done for import and update. However, the DB tables can be very large with several million entries. I think writing the script is not the problem.
The stuff is running on a dedicated machine. Max execution times or memory are no problems. eAccelerator and mysql caching are available (it's just amazing how fast CMSMS can run in such an environment even with complex templates).
I personally would pick Option C, as I think that's something I know how to do. I just wonder whether this is the way to go in terms of good programming and efficiency?
So can anybody give me a push into the right direction? Any other ideas how this could be solved?
Thanks and best
Nils
I am currently working on a kind of CMSMS experiment. For this I have imported some tables of data (own data structure, containing third party content). For simplification the table layout is:
ID: Integer (e.g. "12345")
Name: varchar(80) (e.g. "Some Text Entry")
Summary: text (e.g. "The summary of the topc")
To acccess the data, I want to use pretty URLs like: /page-alias/some-text-entry/
So I plan to use a rewrite rule like this:
RewriteCond %{REQUEST_URI} ^/page-alias/
RewriteRule ^([^/]*)/([^/]*) cmsms/index.php?page=page-alias&item-alias=$2 [QSA,L]
With smarty I capture the get value, pass it on to a plug-in or UDT and check the DB for the corresponding element. Then I can output the other item data.
The URL stuff works without problem. DB import was no problem and using the url to query the data also works (I manually edited some fields.
To problem comes, when I want to find the entry in the DB. Using the regular Name-field doesn't really work. "Some Text Entry" and "some-text-entry" do not match for obvious reason.
I can not just remove the "-" in the item-alias and uppercase the single words first letter to match, as the Name from the DB may contain special characters and such.
I can generate a nice alias from the original name by replacing specials characters and spaces and such with hyphens or ascii equivalents and lowercase the data. it basically does the same as CMSMS when auto creating a page alias.
So I got the single bits working nice but stuck at putting them all together. Probably this is more a mysql question than directly CMSMS related, but probably someone of you knows a quick way

I see these options:
A) Either I transform the Name with mysql-query and then compare it to the item-alias recieved, but then I need to transform a lot of entries and thus might generate a lot of CPU load for each query. Additionally, I can not index the item-aliases in the DB as they are generated on request.
B) I could create a new column named alias. Then I run a mysql query, that reads column name, does string operation and saves the result in the column alias. This would only have to be done once or each time the DB get's updated and is pure mysql.
C) I create the extra column and then run a PHP script that goes column by column and copy saves the text. This would also only be an operation that is done for import and update. However, the DB tables can be very large with several million entries. I think writing the script is not the problem.
The stuff is running on a dedicated machine. Max execution times or memory are no problems. eAccelerator and mysql caching are available (it's just amazing how fast CMSMS can run in such an environment even with complex templates).
I personally would pick Option C, as I think that's something I know how to do. I just wonder whether this is the way to go in terms of good programming and efficiency?
So can anybody give me a push into the right direction? Any other ideas how this could be solved?
Thanks and best
Nils