//----------------------------------------------------------------------
//----------------------------------------------------------------------
//
//		--------------------------------
//		 Gestion d'une Base de donnees:
//		--------------------------------
//
//----------------------------------------------------------------------
//----------------------------------------------------------------------

//	Java --	De base:
//	
import		java.io.*;

//	Java --	Affichage de base:
//	
import		java.awt.*;
import		java.awt.event.*;

//	Java --	RDBM (SGBDR) de base:
//
import		java.sql.*;

//----------------------------------------------------------------------
//----------------------------------------------------------------------

/**
 *	Introspection d'une 'Frame' d'un 'Segment', et gestion SQL.
 */
public
class		ToSQL
	{
// debut de classe
//----------------------------------------------------------------------

public
static
void		a			(String s)
	{
	System.out.println(s);
	}

//----------------------------------------------------------------------

static
Frame		f;

public
static
void		examine		(Frame pf)
	{
	f = pf;
	
	// champs de la clef:
		
	Panel theKey	= (Panel)(f.getComponent(1));
	a("\ntheKey contient "
			+theKey.getComponentCount()
			+" composant(s)");
	for	(int w = 0; w < theKey.getComponentCount(); w++)
		{
		Panel z = (Panel)(theKey.getComponent(w));
		TextComponent  t = (TextComponent)(z.getComponent(0));
		a("\t"+t.getText());
		textWhere = textWhere + t.getText() + " = ? and ";
		textInsert = textInsert + "?,";
		}
	int j = textWhere.lastIndexOf(" and ");
	textWhere = textWhere.substring(0, j);
	a("la clause 'where' sera:\n\t"+textWhere);
	a("l'instruction 'select' sera:\n\tselect * from table "+textWhere);
	a("l'instruction 'delete' sera:\n\tdelete        table "+textWhere);

	// autres champs:
	
	Panel theOther	= (Panel)(f.getComponent(2));
	a("\ntheOther contient "
			+theOther.getComponentCount()
			+" composant(s)");
	for	(int w = 0; w < theOther.getComponentCount(); w++)
		{
		Panel z = (Panel)(theOther.getComponent(w));
		TextComponent  t = (TextComponent)(z.getComponent(0));
		a("\t"+t.getText());
		textSet = textSet + " set "+t.getText()+" = ? ,";
		textInsert = textInsert + "?,";
		}
	j = textSet.lastIndexOf(" ,");
	textSet = textSet.substring(0, j);
	a("l'instruction 'update' sera:\n\tupdate table "+textWhere+textSet); 
	j = textInsert.lastIndexOf(",");
	textInsert = textInsert.substring(0, j)+")";
	a("l'instruction 'insert' sera:\n\t"+textInsert);
	}

//----------------------------------------------------------------------

public
static
Connection	theDBConnection		= null;

public
static
String		textWhere		= " where ";

public
static
String		textSet			= " ";

public
static
String		textInsert		= "insert into table values(";

public
static
Statement	stmtSelect		= null;

public
static
Statement	stmtDelete		= null;

public
static
Statement	stmtInsert		= null;

public
static
Statement	stmtUpdate		= null;

public
static
void		stmtExecuteSelect		()
	{
	}

public
static
void		stmtExecuteDelete		()
	{
	stmtUpdate = new PreparedStatement(textDelete);
	}

public
static
void		stmtExecuteUpdate		()
	{
	}

public
static
void		stmtExecuteInsert		()
	{
	}

//----------------------------------------------------------------------

public
static
void		DBInitialisation		()
						throws		Exception
	{
	theDBConnection	= DriverManager.getConnection
		("jdbc:myDriver:myDatabase", "username", "password");
	}

		
//----------------------------------------------------------------------
// fin de classe
	}

//----------------------------------------------------------------------
//----------------------------------------------------------------------
//----------------------------------------------------------------------
//----------------------------------------------------------------------

