I spent 3-4 hours redesigning this blog. Thanks for the "fleur" template to J. Maloney and Blogcrowds.
Let me know if you like it.
Sunday, September 13, 2009
Friday, September 11, 2009
MySQL foreign keys (MySQL Error Nr. 1005)
12-09-2009 - 12:00
UPDATE:
Well, it seems to me that this topic deserves some more attention, so I'm going to investigate it thoroughly.
From this page I found that:
More in detail, in the rest of the update I'm assuming the following command (as it is reported on the same page I linked above) as reference:
@Dhruva Sagar: I think you were talking about this one:
@payal: Check this (same page as above...):
Furthermore I suggest using the following command to check when errors occur: SHOW ENGINE INNODB STATUS, which displays a detailed explanation of the most recent foreign key error in the server.
I'm trying to replicate this error today; I'll drop you the results as soon as I can.
----------------- old updates -----------------
27-08-2007 - 10:08 (OLD UPDATE!!!)
UPDATE:
It seems the problem is caused by the "ON UPDATE" and "ON DELETE" clauses: they have to be set to the same policy, i.e. you have to write "ADD CONSTRAINT 'new_fk_constraint' FOREIGN KEY 'new_fk_constraint' ('fieldA1') REFERENCES 'tableB' ('fieldB2') ON DELETE RESTRICT ON UPDATE RESTRICT" or "ON DELETE UPDATE ON UPDATE UPDATE", while "ON DELETE SET NULL ON UPDATE RESTRICT" won't work.
Indexes are not the cause of the problem: when you create a foreign key an index for the field involved on the foreign key is automatically created by the MySQL environment, so you don't need to manually create it before adding the foreign key (read: "Bull-Shit at 09:41, Good-Shit at 10:08").
27-08-2007 - 09:41 (OLD UPDATE!!!)
If you want to place a foreign key from field 1 on table A to field 2 on table B, first of all you need to create an index for the field 1 on table A.
If you don't create the index before attempting to create the foreign key you are likely to be stopped by the error "MySQL Error Nr. 1005- Can't create table...".
I experienced this situation while using InnoDB.
UPDATE:
Well, it seems to me that this topic deserves some more attention, so I'm going to investigate it thoroughly.
From this page I found that:
a table [...] must have indexes on the referenced keys. If these are not satisfied [read: "if they are not present for those keys"], MySQL returns error number 1005 and refers to error 150 in the error message.
More in detail, in the rest of the update I'm assuming the following command (as it is reported on the same page I linked above) as reference:
[CONSTRAINT [symbol]] FOREIGN KEY [index_name] (index_col_name, ...) REFERENCES tbl_name (index_col_name,...) [ON DELETE reference_option] [ON UPDATE reference_option]
@Dhruva Sagar: I think you were talking about this one:
If the CONSTRAINT symbol clause is given, the symbol value must be unique in the database. If the clause is not given, InnoDB creates the name automatically.
@payal: Check this (same page as above...):
InnoDB supports foreign key references within a table. In these cases, “child table records” really refers to dependent records within the same table.
Furthermore I suggest using the following command to check when errors occur: SHOW ENGINE INNODB STATUS, which displays a detailed explanation of the most recent foreign key error in the server.
I'm trying to replicate this error today; I'll drop you the results as soon as I can.
----------------- old updates -----------------
27-08-2007 - 10:08 (OLD UPDATE!!!)
UPDATE:
It seems the problem is caused by the "ON UPDATE" and "ON DELETE" clauses: they have to be set to the same policy, i.e. you have to write "ADD CONSTRAINT 'new_fk_constraint' FOREIGN KEY 'new_fk_constraint' ('fieldA1') REFERENCES 'tableB' ('fieldB2') ON DELETE RESTRICT ON UPDATE RESTRICT" or "ON DELETE UPDATE ON UPDATE UPDATE", while "ON DELETE SET NULL ON UPDATE RESTRICT" won't work.
Indexes are not the cause of the problem: when you create a foreign key an index for the field involved on the foreign key is automatically created by the MySQL environment, so you don't need to manually create it before adding the foreign key (read: "Bull-Shit at 09:41, Good-Shit at 10:08").
27-08-2007 - 09:41 (OLD UPDATE!!!)
If you want to place a foreign key from field 1 on table A to field 2 on table B, first of all you need to create an index for the field 1 on table A.
If you don't create the index before attempting to create the foreign key you are likely to be stopped by the error "MySQL Error Nr. 1005- Can't create table...".
I experienced this situation while using InnoDB.
Monday, August 31, 2009
How to save an XML file in Java and Eclipse
One problem I faced today was saving the content of an XML document (org.w3c.dom.Document) to a newly created file.
The file I was outputting to was an Eclipse abstraction (precisely org.eclipse.core.resources.IFile) of a regular one and the method offered by this IFile for setting its contents is "IFile.setContents(InputStream source, boolean force, boolean keepHistory, IProgressMonitor monitor)".
I needed to bridge the gap between that org.w3c.dom.Document and the InputStream required by "IFile.setContents()", and here's the way I did it:
The main classes being used here are from package "javax.xml.transform", with the method "Transformer.transform(javax.xml.transform.dom.Source source, Result result)" basically taking care of all the stuff.
I'm going to package this one into a library called "LifeSavingUtilities"...
The file I was outputting to was an Eclipse abstraction (precisely org.eclipse.core.resources.IFile) of a regular one and the method offered by this IFile for setting its contents is "IFile.setContents(InputStream source, boolean force, boolean keepHistory, IProgressMonitor monitor)".
I needed to bridge the gap between that org.w3c.dom.Document and the InputStream required by "IFile.setContents()", and here's the way I did it:
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try
{
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer();
transformer.setOutputProperty(OutputKeys.METHOD, "xml");
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
PrintWriter writer =
new PrintWriter(outputStream);
transformer.transform(new DOMSource(document),
new XMLWriter(writer).toXMLResult());
writer.flush();
}
catch (TransformerConfigurationException exc)
{
// DEBUG
exc.printStackTrace();
}
catch (TransformerException exc)
{
// DEBUG
exc.printStackTrace();
}
InputStream source = new ByteArrayInputStream(outputStream.toByteArray());
The main classes being used here are from package "javax.xml.transform", with the method "Transformer.transform(javax.xml.transform.dom.Source source, Result result)" basically taking care of all the stuff.
I'm going to package this one into a library called "LifeSavingUtilities"...
Friday, July 17, 2009
Copy-right?
The "new" Italia.it is tragicomically "inspired" to Spain.info.
Warning: I'm Italian, despite our current prime minister and the Italian people that vote for him.
Warning: I'm Italian, despite our current prime minister and the Italian people that vote for him.
Copy-right?
Il "nuovo" Italia.it è spudoratamente copiato dal suo omologo spagnolo, Spain.info.
Esiste una parola nella nostra lingua per esprimere cosa penso di Italia.it: "tragicommedia"
Esiste una parola nella nostra lingua per esprimere cosa penso di Italia.it: "tragicommedia"
Tuesday, July 14, 2009
Wednesday, May 13, 2009
La ricerca (della felicità e) del lavoro
Una mia amica cerca un buon lavoro qui in Sardegna.
Attualmente vive e lavora a Milano (Blulabs e SISAL) ma vorrebbe tornare dalle nostre parti. Se qualcuno avesse notizia di un'opportunità lavorativa per lei non esiti a contattarmi al mio indirizzo di posta (o, per i fortunati che lo hanno, al mio numero di cellulare).
Qualche informazione professionale su di lei:
Fatemi sapere, grazie.
Attualmente vive e lavora a Milano (Blulabs e SISAL) ma vorrebbe tornare dalle nostre parti. Se qualcuno avesse notizia di un'opportunità lavorativa per lei non esiti a contattarmi al mio indirizzo di posta (o, per i fortunati che lo hanno, al mio numero di cellulare).
Qualche informazione professionale su di lei:
- Laurata nel 2007 a Sassari nella Facoltà di Economia, con indirizzo in Nuove Tecnologie
- Nel 2008 ha partecipato al Master in Marketing & Comunicazione proposto dalla Facoltà di Economia di Torino
- Stage del Master svolto a Torino nell'Area Web di Alpitour (lancio del sito e-mall, analisi di mercato e comparazione con i competitor, cura di alcuni aspetti del sito come l'inserimento testi e la comunicazione mediante l'utilizzo della piattaforma Documentum, un po di SEO con successiva verifica del raggiungimento degli obiettivi della campagna, scelta delle keywords e delle creatività per il lancio di alcune campagne google con l'utilizzo di Google AdSense)
- Esperienze all'estero: Progetto Erasmus svolto a Valencia, due mesi e mezzo ad Amsterdam (dove ha maturato un buon inglese)
Fatemi sapere, grazie.
Monday, April 6, 2009
Monday, March 30, 2009
PD 2009 Professional Edition
Franceschini somiglia a Bill Gates (e viceversa).
Non ho ancora capito se sperare che sia una coincidenza o il contrario.
Non ho ancora capito se sperare che sia una coincidenza o il contrario.
Friday, March 20, 2009
Laboratorio analisi paralizzato
Gli effetti del cambio di giunta nella Regione Sardegna cominciano a farsi sentire. Per non meglio specificati "problemi" che sembrano affliggere la rete della Regione il laboratorio analisi del Policlinico Universitario di Monserrato stamattina non ha potuto effettuare analisi per le persone che stavano li ad aspettare.
Sembrerebbe che sia stato anche richiesto l'intervento delle Forze dell'Ordine (che ci scappi qualche denuncia?).
Immagino che il Signorino Cappellacci abbia già iniziato a smontare le cose buone che erano state fatte dal suo predecessore...
A chi mi accuserà di paranoia ci tengo a ricordare che "a pensar male a volte si fa torto, ma spesso [quasi sempre nell'italietta odierna N.d.A.] ci si azzecca".
Come
Sembrerebbe che sia stato anche richiesto l'intervento delle Forze dell'Ordine (che ci scappi qualche denuncia?).
Immagino che il Signorino Cappellacci abbia già iniziato a smontare le cose buone che erano state fatte dal suo predecessore...
A chi mi accuserà di paranoia ci tengo a ricordare che "a pensar male a volte si fa torto, ma spesso [quasi sempre nell'italietta odierna N.d.A.] ci si azzecca".
Come
Subscribe to:
Posts (Atom)
