// Decompiled by DJ v2.6.6.51 Copyright 2000 Atanas Neshkov  Date: 6/15/2001 17:43:27
// Home Page : http://members.fortunecity.com/neshkov/dj.html  - Check often for new version!
// Decompiler options: packimports(3) 
// Source File Name:   com/macromedia/generator/app/SqlDataSource

package com.macromedia.generator.app;

import java.sql.*;
import java.util.Vector;

// Referenced classes of package com.macromedia.generator.app:
//            FlashCommandLog

public class SqlDataSource
{

    public SqlDataSource()
    {
        szResourceBundle = "com.macromedia.generator.resources.DataSourceData";
    }

    private boolean _mth0104(SQLWarning sqlwarning)
        throws SQLException
    {
        boolean flag = false;
        if(sqlwarning != null)
        {
            log.logMessage(szResourceBundle, "SQLWarning", "");
            for(; sqlwarning != null; sqlwarning = sqlwarning.getNextWarning())
            {
                log.logMessage(szResourceBundle, "SQLState", sqlwarning.getSQLState());
                log.logMessage(szResourceBundle, "SQLMessage", sqlwarning.getMessage());
                log.logMessage(szResourceBundle, "SQLVendor", sqlwarning.getErrorCode() + "\n");
            }

            flag = true;
        }
        return flag;
    }

    public String[][] getData(String s, String s1, String s2, String s3)
    {
        String as[][] = null;
        try
        {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            Connection connection = DriverManager.getConnection(s, s1, s2);
            _mth0104(connection.getWarnings());
            java.sql.DatabaseMetaData databasemetadata = connection.getMetaData();
            Statement statement = connection.createStatement();
            ResultSet resultset = statement.executeQuery(s3);
            as = _mth0105(resultset);
            resultset.close();
            statement.close();
            connection.close();
        }
        catch(SQLException sqlexception)
        {
            log.logMessage(szResourceBundle, "SQLWarning", "");
            for(; sqlexception != null; sqlexception = sqlexception.getNextException())
            {
                log.logMessage(szResourceBundle, "SQLState", sqlexception.getSQLState());
                log.logMessage(szResourceBundle, "SQLMessage", sqlexception.getMessage());
                log.logMessage(szResourceBundle, "SQLVendor", sqlexception.getErrorCode() + "\n");
            }

            as = null;
        }
        catch(Exception _ex)
        {
            as = null;
        }
        if(as != null && log != null && log.logLevel() > 2)
        {
            log.logMessage(szResourceBundle, "DumpData", s + s3);
            int i = as.length;
            StringBuffer stringbuffer = new StringBuffer(128);
            for(int j = 0; j < i; j++)
            {
                stringbuffer.setLength(0);
                stringbuffer.append(j + 1);
                stringbuffer.append(": ");
                int k = as[j].length;
                for(int l = 0; l < k; l++)
                {
                    if(l > 0)
                        stringbuffer.append(", ");
                    stringbuffer.append(as[j][l]);
                }

                log.logMessage(szResourceBundle, "DumpRow", stringbuffer.toString());
            }

        }
        return as;
    }

    private String[][] _mth0105(ResultSet resultset)
        throws SQLException
    {
        Object obj = null;
        String as2[][] = null;
        Vector vector = new Vector();
        ResultSetMetaData resultsetmetadata = resultset.getMetaData();
        int i = resultsetmetadata.getColumnCount();
        if(i > 0)
        {
            String as[] = new String[i];
            for(int j = 0; j < i; j++)
                as[j] = resultsetmetadata.getColumnLabel(j + 1);

            vector.addElement(as);
            for(String as1[] = null; resultset.next(); as1 = null)
            {
                as1 = new String[i];
                for(int k = 0; k < i; k++)
                {
                    as1[k] = resultset.getString(k + 1);
                    if(as1[k] == null)
                        as1[k] = "";
                }

                vector.addElement(as1);
            }

            if(!vector.isEmpty())
            {
                int l = vector.size();
                as2 = new String[l][];
                for(int i1 = 0; i1 < l; i1++)
                    as2[i1] = (String[])vector.elementAt(i1);

            }
        }
        return as2;
    }

    public void setLog(FlashCommandLog flashcommandlog)
    {
        log = flashcommandlog;
    }

    protected FlashCommandLog log;
    protected String szResourceBundle;
}