default characterset of function string parameter
Dear MySQL fans, I am checking MySQL 5.0 to use multibyte strings, Japanese. When I use char type parameter without CHARACTER SET clause, parameter's character set is not the database character set but latin1. 17.2.1. CREATE PROCEDURE says: For character data types, if there is a CHARACTER SET clause in the declaration, the specified character set and its default collation are used. If there is no such clause, the database character set and collation are used. (These are given by the values of the character_set_database and collation_database system variables.) Following is my test: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - mysql SET @@character_set_database=eucjpms; Query OK, 0 rows affected (0.00 sec) mysql SHOW VARIABLES LIKE 'character\_set\_%'; +--+-+ | Variable_name| Value | +--+-+ | character_set_client | eucjpms | | character_set_connection | eucjpms | | character_set_database | eucjpms | | character_set_results| eucjpms | | character_set_server | latin1 | | character_set_system | utf8| +--+-+ 6 rows in set (0.00 sec) mysql DELIMITER // mysql CREATE FUNCTION parametercharset( s CHAR(20) ) - RETURNS CHAR(50) CHARACTER SET binary - DETERMINISTIC RETURN CONCAT( s, ':', CHARSET(s) ); - // Query OK, 0 rows affected (0.00 sec) mysql DELIMITER ; mysql SELECT parametercharset('hello'); ++ | parametercharset('hello') | ++ | hello:latin1 | ++ 1 row in set (0.00 sec) mysql - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Hirofumi Fujiwara (Tokyo JAPAN) enjoy JAVA and Puzzle World [EMAIL PROTECTED] http://www.pro.or.jp/~fuji/index-eng.html [EMAIL PROTECTED] Puzzle Japanhttp://www.puzzle.jp/ My SUDOKU Probs http://www.pro.or.jp/~fuji/sudoku/problems/ -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]
Help on query joining a 3rd table
Hello! I am building a query to get a monthly total for receipts and receipts plus TAX. My problem is the TAX, it can be different for each receipt. I need help on including and relating each TAX value/id with each receipt, like receipt_items.price * 1.21 etc. The tables are like the following example: Table receipts: id | id_tax | date 112005-12-31 212006-01-01 322006-01-25 ... Table receipt_items: id | id_receipt | price (exc tax) 111000 221000 ... Table tax: id | tax (%) 119 221 So far I have: SELECT SUM(receipt_items.price) AS total , (SUM(receipt_items.price) * [-help here-]) AS total_plus_tax FROM receipt_items, receipts WHERE receipt_items.id_receipt = receipts.id AND MONTH(receipts.date)=.$month. AND YEAR(receipts.date)=.$year. Thanks in advance. Pedro. -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]
Help on query joining a 3rd table
Solved. Thanks. -Mensagem original- De: pedro mpa [mailto:[EMAIL PROTECTED] Enviada: domingo, 29 de Janeiro de 2006 18:25 Para: mysql@lists.mysql.com Assunto: Help on query joining a 3rd table Hello! I am building a query to get a monthly total for receipts and receipts plus TAX. My problem is the TAX, it can be different for each receipt. I need help on including and relating each TAX value/id with each receipt, like receipt_items.price * 1.21 etc. The tables are like the following example: Table receipts: id | id_tax | date 112005-12-31 212006-01-01 322006-01-25 ... Table receipt_items: id | id_receipt | price (exc tax) 111000 221000 ... Table tax: id | tax (%) 119 221 So far I have: SELECT SUM(receipt_items.price) AS total , (SUM(receipt_items.price) * [-help here-]) AS total_plus_tax FROM receipt_items, receipts WHERE receipt_items.id_receipt = receipts.id AND MONTH(receipts.date)=.$month. AND YEAR(receipts.date)=.$year. Thanks in advance. Pedro. -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED] -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]
Support between MySQL and PHP
Hi all. I figured this question was suitable for both the MySQL list and the PHP-General list. Here's what I'm running into. I just installed MySQL5 and currently have PHP 4.3.11 installed. I am wanting to connect to the mysql database on localhost, but I get the following results: -- ? $link = mysql_connect('localhost', 'user', 'password'); ? Client does not support authentication protocol requested by server; consider upgrading MySQL client -- Well, I have the lastest stable version of MySQL, so I did some more research on what the problem might be. When I checked my information for PHP using phpinfo(), it gave me the Client API version for MySQL was 3.23.49. So, I'm thinking my version of PHP cannot connect to my version of MySQL. I then considered if I installed the MySQLi extension for PHP (supports versions of MySQL 4.1), would that help me? Or, if I just upgraded PHP to version 5, would that help me? Does anyone have any suggestions on the direction I should go? Thanks in advance, ~Philip -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]
display a hierarchic tree
I have the following table: mysql select * from link_categories; ++---+-+---+---+-+ | id | level | category_id | category | parent_id | deleted | ++---+-+---+---+-+ | 1 | 1 |1000 | Software | 0 | 0 | | 2 | 1 |2000 | Harware | 0 | 0 | | 3 | 2 |1001 | Virenscanner | 1000 | 0 | | 4 | 2 |1003 | Packprogramme | 1000 | 0 | | 5 | 3 |1004 | Linux | 1001 | 0 | | 6 | 3 |1005 | Windows | 1001 | 0 | | 7 | 4 |1006 | Windows XP| 1005 | 0 | | 8 | 2 |1007 | Sniffer | 1000 | 0 | | 9 | 4 |1008 | Debian Woody | 1004 | 0 | | 10 | 1 | 10 | Vermischtes | 0 | 0 | ++---+-+---+---+-+ 10 rows in set (0.24 sec) and I want to display a tree like: Software Virenscanner Linux Debian Woody Windows Windowsd XP Packprogramm Sniffer Hardware Vermischtes Can someone give me hint how to build a query? I run MySQL 4.1.x and 5.0.x and I use PHP. Thanx. -- fvgi242ss | wlanhacking.de -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]
Re: display a hierarchic tree
Jochen, ...I want to display a tree like: Software Virenscanner Linux Debian Woody Windows Windowsd XP Packprogramm Sniffer Hardware Vermischtes It looks more like a parts explosion than a tree (ie it seems to have more than one root node). Perhaps you can hack this parts explosion example into the shape you need ... DROP TABLE IF EXISTS bom; CREATE TABLE bom ( level SMALLINT, nodeID SMALLINT, parentID SMALLINT, qty DECIMAL(10,2), cost DECIMAL(10,2), leftedge SMALLINT, rightedge SMALLINT ); DROP TABLE IF EXISTS edges; CREATE TABLE edges LIKE tree; DROP PROCEDURE IF EXISTS ShowComponents; DELIMITER | CREATE PROCEDURE ShowComponents( IN root INT ) BEGIN DECLARE thischild, thisparent, rows, maxrightedge INT DEFAULT 0; DECLARE thislevel, nextedgenum INT DEFAULT 1; DECLARE thisqty, thiscost DECIMAL(10,2); TRUNCATE edges; TRUNCATE bom; INSERT INTO edges SELECT childID,parentID FROM assemblies WHERE assemblyRoot = root; SET maxrightedge = 2 * (1 + (SELECT COUNT(*) FROM edges)); INSERT INTO bom VALUES( thislevel, root, 0, 0, 0, nextedgenum, maxrightedge ); SET nextedgenum = nextedgenum + 1; WHILE nextedgenum maxrightedge DO -- How many children of this node remain in the edges table? SET rows = ( SELECT COUNT(*) FROM bom AS s INNER JOIN edges AS t ON s.nodeID=t.parentID AND s.level=thislevel ); IF rows 0 THEN -- There is at least one child edge. -- Compute qty and cost, insert into bom, delete from edges. BEGIN -- Alas MySQL nulls MIN(t.childid) when we combine the next two queries SET thischild = ( SELECT MIN(t.childID) FROM bom AS s INNER JOIN edges AS t ON s.nodeID=t.parentID AND s.level=thislevel ); SET thisparent = ( SELECT DISTINCT t.parentID FROM bom AS s INNER JOIN edges AS t ON s.nodeID=t.parentID AND s.level=thislevel ); SET thisqty = ( SELECT quantity FROM assemblies WHERE assemblyroot = root AND childID = thischild AND parentID = thisparent ); SET thiscost = ( SELECT a.assemblycost + (thisqty * (i.purchasecost + i.assemblycost )) FROM assemblies AS a INNER JOIN items AS i ON a.childID = i.itemID WHERE assemblyroot = root AND a.parentID = thisparent AND a.childID = thischild ); INSERT INTO bom VALUES(thislevel+1, thischild, thisparent, thisqty, thiscost, nextedgenum, NULL); DELETE FROM edges WHERE childID = thischild AND parentID=thisparent; SET thislevel = thislevel + 1; SET nextedgenum = nextedgenum + 1; END; ELSE BEGIN -- Set rightedge, remove item from edges UPDATE bom SET rightedge=nextedgenum, level = -level WHERE level = thislevel; SET thislevel = thislevel - 1; SET nextedgenum = nextedgenum + 1; END; END IF; END WHILE; SET rows := ( SELECT COUNT(*) FROM edges ); IF rows 0 THEN SELECT 'Orphaned rows remain'; ELSE -- Percolate qty values up the graph UPDATE bom AS c INNER JOIN bom AS p ON p.leftedge c.leftedge AND p.rightedge c.rightedge AND p.level = c.level + 1 AND p.qty 1 SET c.qty = c.qty * p.qty, c.cost = c.cost * p.qty; -- Total SET thiscost = (SELECT SUM(qty) FROM bom); UPDATE bom SET qty = 1, cost = thiscost WHERE nodeID = root; -- Show the result SELECT CONCAT(Space(Abs(level)*2),ItemName(nodeid)) AS Item, ROUND(qty,2) AS Qty, ROUND(cost, 2) AS Cost FROM bom ORDER BY leftedge; END IF; END; | DELIMITER ; PB - Jochen Kaechelin wrote: I have the following table: mysql select * from link_categories; ++---+-+---+---+-+ | id | level | category_id | category | parent_id | deleted | ++---+-+---+---+-+ | 1 | 1 |1000 | Software | 0 | 0 | | 2 | 1 |2000 | Harware | 0 | 0 | | 3 | 2 |1001 | Virenscanner | 1000 | 0 | | 4 | 2 |1003 | Packprogramme | 1000 | 0 | | 5 | 3 |1004 | Linux | 1001 | 0 | | 6 | 3 |1005 | Windows | 1001 | 0 | | 7 | 4 |1006 | Windows XP| 1005 | 0 | | 8 | 2 |1007 | Sniffer | 1000 | 0 | | 9 | 4 |1008 | Debian Woody | 1004 | 0 | | 10 | 1 | 10 | Vermischtes | 0 | 0 | ++---+-+---+---+-+ 10 rows in set (0.24 sec) and I want to display a tree like: Software Virenscanner Linux Debian Woody
Re: Support between MySQL and PHP
Hi Philip. I'm wondering if you have mysql server version 3.23.49 still running on your machine? If so, version 5 would not start up, as it would not be allowed access to port 3306. Try doing my_print_defaults mysqld and my_print_defaults client mysql from a root shell and see what values you get returned. HTH Keith In theory, theory and practice are the same; In practice they are not. On Sun, 29 Jan 2006, Philip R. Thompson wrote: To: mysql@lists.mysql.com, php-general@lists.php.net From: Philip R. Thompson [EMAIL PROTECTED] Subject: Support between MySQL and PHP Hi all. I figured this question was suitable for both the MySQL list and the PHP-General list. Here's what I'm running into. I just installed MySQL5 and currently have PHP 4.3.11 installed. I am wanting to connect to the mysql database on localhost, but I get the following results: -- ? $link = mysql_connect('localhost', 'user', 'password'); ? Client does not support authentication protocol requested by server; consider upgrading MySQL client -- Well, I have the lastest stable version of MySQL, so I did some more research on what the problem might be. When I checked my information for PHP using phpinfo(), it gave me the Client API version for MySQL was 3.23.49. So, I'm thinking my version of PHP cannot connect to my version of MySQL. I then considered if I installed the MySQLi extension for PHP (supports versions of MySQL 4.1), would that help me? Or, if I just upgraded PHP to version 5, would that help me? Does anyone have any suggestions on the direction I should go? Thanks in advance, ~Philip k -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]
Re: display a hierarchic tree
Hi Jochen. An alternative approach could be to pull all the values out of the database using select * from ..., and then build the tree-structure in your application logic. Insert the relevant values returned from mysql in the appropriate places of the tree-structure in the app code. Keith In theory, theory and practice are the same; In practice they are not. On Sun, 29 Jan 2006, Jochen Kaechelin wrote: To: mysql@lists.mysql.com From: Jochen Kaechelin [EMAIL PROTECTED] Subject: display a hierarchic tree I have the following table: mysql select * from link_categories; ++---+-+---+---+-+ | id | level | category_id | category | parent_id | deleted | ++---+-+---+---+-+ | 1 | 1 |1000 | Software | 0 | 0 | | 2 | 1 |2000 | Harware | 0 | 0 | | 3 | 2 |1001 | Virenscanner | 1000 | 0 | | 4 | 2 |1003 | Packprogramme | 1000 | 0 | | 5 | 3 |1004 | Linux | 1001 | 0 | | 6 | 3 |1005 | Windows | 1001 | 0 | | 7 | 4 |1006 | Windows XP| 1005 | 0 | | 8 | 2 |1007 | Sniffer | 1000 | 0 | | 9 | 4 |1008 | Debian Woody | 1004 | 0 | | 10 | 1 | 10 | Vermischtes | 0 | 0 | ++---+-+---+---+-+ 10 rows in set (0.24 sec) and I want to display a tree like: Software Virenscanner Linux Debian Woody Windows Windowsd XP Packprogramm Sniffer Hardware Vermischtes Can someone give me hint how to build a query? I run MySQL 4.1.x and 5.0.x and I use PHP. Thanx. -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]
Re: MySQL ignores foreign key relationships between tables?
Ferindo Middleton Jr wrote: Ferindo Middleton Jr wrote: Paul DuBois wrote: At 17:56 -0500 1/28/06, Ferindo Middleton Jr wrote: I have two tables, registration schedules, that look like this: CREATE TABLE registration ( idSERIAL NOT NULL UNIQUE, firstnameVARCHAR(256) NOT NULL, middlenameTEXT, lastnameVARCHAR(256), suffix TEXT, schedule_id INTEGER REFERENCES schedules(id), ); CREATE TABLE schedules ( id SERIAL NOT NULL UNIQUE, start_date DATE NOT NULL, end_date DATE NOT NULL, ); The registration table above references the the schedules table via the schedule_id. Why does MySQL allow a row created in the schedules table be DELETED if it has a matching schedule_id in the registration table. These two tables share a relationship based on registration.schedule_id schedules.id. I've tried this same syntax in PostgreSQL and it doesn't allow the schedules.id record to be deleted without first removing any records in the registration table which carry a matching schedule_id record. Isn't that the point of a relational database?- TO CHECK RELATIONSHIPS between tables and enforce that those relationships aren't broken? I find it disappointing that MySQL ignores this relationship. Add ENGINE = InnoDB to the end of your table definitions. Foreign keys are supported only for InnoDB tables in MySQL. I am using InnoDB. I use MySQL Administrator and InnoDB is what it says all my tables are already using so it must have chosen that by default or something. Does this mean that I shouldn't have been able to delete records from my schedules table above that had a foreign key in the registration table? Thanks. Ferindo Paul, I discovered that this foreign key constraint wasn't present in these tables anymore due to my own action. You see, I had backed up my database before using MySQL Administrator, not knowing that is was backing up such tables constructs as foreign keys, etc. So the database I'm looking at today isn't the same database I originally created with the same constraints... I'm going to stop using MySQL Administrator... using it seems somewhat misleading and it made me think that the tables sand the constraints I made on them were still present. Thanks. Ferindo I take it back. I imported the data in my database above without using the MySQL Administrator backup utility and first re-CREATEing the db tables in my database But still MySQL still allows for cross-referenced records between my schedules table and the registration table schedule id field to be deleted. Why do you think this is happening. Is this yet another feature that MySQL doesn't really support yet? Is MySQL totally ignoring the REFERENCES part of the schedule_id field from my registration table above. I've determined that I'm using InnoDB so why isn't it working? Ferindo -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]
Can't reload from dump file
We have had some problems with corrupt data due to running out of space recently. I wanted to repair the tables so I backed up our database by dumping to a file with mysqldump. I then tried to repair the database and had some problems with that. I stopped MySQL and moved the database to database.old and restarted the database. I wanted to import the dump file. As it is 700 MB it takes a while to load. I got this error [EMAIL PROTECTED] backups]# mysql -u root -prt3.sql Enter password: ERROR 1005 (HY000) at line 694: Can't create table './rt3/Attributes.frm' (errno: 121) and in the error file: 060129 19:27:32 InnoDB: Error: table `rt3/Attributes` already exists in InnoDB internal InnoDB: data dictionary. Have you deleted the .frm file InnoDB: and not used DROP TABLE? Have you used DROP DATABASE InnoDB: for InnoDB tables in MySQL version = 3.23.43? InnoDB: See the Restrictions section of the InnoDB manual. InnoDB: You can drop the orphaned table inside InnoDB by InnoDB: creating an InnoDB table with the same name in another InnoDB: database and copying the .frm file to the current database. InnoDB: Then MySQL thinks the table exists, and DROP TABLE will InnoDB: succeed. InnoDB: You can look for further help from InnoDB: http://dev.mysql.com/doc/mysql/en/InnoDB_troubleshooting_datadict.html What can I do? -- Chris Mason NetConcepts (264) 497-5670 Fax: (264) 497-8463 Int: (305) 704-7249 Fax: (815)301-9759 UK 44.207.183.0271 Cell: 264-235-5670 Yahoo IM: [EMAIL PROTECTED] -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]
Re: MySQL ignores foreign key relationships between tables?
At 18:03 -0500 1/29/06, Ferindo Middleton Jr wrote: Ferindo Middleton Jr wrote: Ferindo Middleton Jr wrote: Paul DuBois wrote: At 17:56 -0500 1/28/06, Ferindo Middleton Jr wrote: I have two tables, registration schedules, that look like this: CREATE TABLE registration ( idSERIAL NOT NULL UNIQUE, firstnameVARCHAR(256) NOT NULL, middlenameTEXT, lastnameVARCHAR(256), suffix TEXT, schedule_id INTEGER REFERENCES schedules(id), ); CREATE TABLE schedules ( id SERIAL NOT NULL UNIQUE, start_date DATE NOT NULL, end_date DATE NOT NULL, ); The registration table above references the the schedules table via the schedule_id. Why does MySQL allow a row created in the schedules table be DELETED if it has a matching schedule_id in the registration table. These two tables share a relationship based on registration.schedule_id schedules.id. I've tried this same syntax in PostgreSQL and it doesn't allow the schedules.id record to be deleted without first removing any records in the registration table which carry a matching schedule_id record. Isn't that the point of a relational database?- TO CHECK RELATIONSHIPS between tables and enforce that those relationships aren't broken? I find it disappointing that MySQL ignores this relationship. Add ENGINE = InnoDB to the end of your table definitions. Foreign keys are supported only for InnoDB tables in MySQL. I am using InnoDB. I use MySQL Administrator and InnoDB is what it says all my tables are already using so it must have chosen that by default or something. Does this mean that I shouldn't have been able to delete records from my schedules table above that had a foreign key in the registration table? Thanks. Ferindo Paul, I discovered that this foreign key constraint wasn't present in these tables anymore due to my own action. You see, I had backed up my database before using MySQL Administrator, not knowing that is was backing up such tables constructs as foreign keys, etc. So the database I'm looking at today isn't the same database I originally created with the same constraints... I'm going to stop using MySQL Administrator... using it seems somewhat misleading and it made me think that the tables sand the constraints I made on them were still present. Thanks. Ferindo I take it back. I imported the data in my database above without using the MySQL Administrator backup utility and first re-CREATEing the db tables in my database But still MySQL still allows for cross-referenced records between my schedules table and the registration table schedule id field to be deleted. Why do you think this is happening. Is this yet another feature that MySQL doesn't really support yet? Is MySQL totally ignoring the REFERENCES part of the schedule_id field from my registration table above. I've determined that I'm using InnoDB so why isn't it working? Ferindo Looking at: http://dev.mysql.com/doc/refman/5.0/en/innodb-foreign-key-constraints.html I see no examples that are missing FOREIGN KEY. What happens if you change your table definition to change: schedule_id INTEGER REFERENCES schedules(id) To: schedule_id INTEGER, FOREIGN KEY (schedule_id) REFERENCES schedules(id) Also, SERIAL is an alias for a BIGINT type, so you'll probably need to make schedule_id a BIGINT. -- Paul DuBois, MySQL Documentation Team Madison, Wisconsin, USA MySQL AB, www.mysql.com -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]
Revert using Binlog
Am hoping someone can give me the safest advice here. Using 4.1 and InnoDB, someone in an attempt to be helpful set up a lot of foreign key constraints. However... ON DELETE CASCADE When we needed RESTRICT. Net effect? Some editing today lead to cries of Where has half the data gone? We have the binlog, and know the point at which the erroneous stuff happened - however, no backup exists, so I can't roll forward from that (don't ask)... Is it at all possible to rollback using the binlog to that point? Or is it time to get back to manual data entry? Any help greatly appreciated. Rob -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]