for list database, table, view......

//In uppsrc/plugin/sqlite3/Sqlite3.h
//REPLACE the OLD code ---------------------------------------------------------------
	virtual Vector<String> EnumDatabases();				// Currently does not detect attached DBs, just returns current filename
	virtual Vector<String> EnumTables(String database);	// Currently ignores database string
//	virtual Vector<SqlColumnInfo> EnumColumns(String database, String table);	// Currently ignores database string


// WITH the NEW code -----------------------------------------------------------------
	virtual Vector<String> EnumDatabases();
	virtual Vector<String> EnumTables(String database);
	virtual Vector<String> EnumViews(String database);
	virtual Vector<SqlColumnInfo> EnumColumns(String database, String table);

//-END-----------------------------------------------------------------------------


//In uppsrc/plugin/sqlite3/Sqlite3upp.cpp
//REPLACE the OLD code ---------------------------------------------------------------
Vector<String> Sqlite3Session::EnumDatabases() {
	// In theory, sqlite3 can "ATTACH" multiple databases (up to 10).
	// However, I don't know how to list them.
	Vector<String> out;
	out.Add(current_dbname);
	return out;
}

Vector<String> Sqlite3Session::EnumTables(String database) {
	// Ignores database
	Vector<String> out;
	Sql sql(*this);
	sql*Select(SqlId("tbl_name")).From(SqlId("sqlite_master")).Where(SqlId("type")=="table");
	while (sql.Fetch())
		out.Add(sql[0]);
	return out;
}

/*
Vector<SqlColumnInfo> Sqlite3Session::EnumColumns(String database, String table) {
	Vector<SqlColumnInfo> out;
	Sqlite3Connection sql(*this,db);
	sqlite3_stmt* s = sql.Compile(Format("select * from %s limit 0;",table));
	int retcode = sqlite3_step(s);
	ASSERT(SQLITE_DONE == retcode);
	for (int i = 0; i < sqlite3_column_count(s); i++) {
		SqlColumnInfo info;
		info.name = sqlite3_column_name(s,i);
		switch (sqlite3_column_type(s, i)) {
	    case 1:
	        info.type = INT_V;
	        break;
	    case 2:
	        info.type = DOUBLE_V;
	        break;
	    default:
	        info.type = STRING_V;
		}
		info.width = info.decimals = info.scale = info.prec = 0;
		out.Add(info);
	}
	sqlite3_reset(s);

	return out;
}
*/



//---------------------------------------------------------------------------------------
//WITH the NEW code----------------------------------------------------------------------
Vector<String> Sqlite3Session::EnumDatabases() {
        Vector<String> out;
	Sql sql(*this);	
	sql.Execute("PRAGMA database_list;");
	while (sql.Fetch())
                out.Add(sql[1]);  // sql[1] is database name, sql[2] is filename
	return out;
}

Vector<String> Sqlite3Session::EnumTables(String database) {
	Vector<String> out;
        String dbn=database;
        if(dbn.IsEmpty()) dbn=current_dbname; // for backward compatibility
	Sql sql(*this);
        sql.Execute("SELECT name FROM "+dbn+".sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%' ORDER BY 1;");
	while (sql.Fetch())
		out.Add(sql[0]);
	return out;
}

Vector<String> Sqlite3Session::EnumViews(String database) {
	Vector<String> out;
        String dbn=database;
        if(dbn.IsEmpty()) dbn=current_dbname;
	Sql sql(*this);
        sql.Execute("SELECT name FROM "+dbn+".sqlite_master WHERE type='view' AND name NOT LIKE 'sqlite_%' ORDER BY 1;");
	while (sql.Fetch())
		out.Add(sql[0]);
	return out;
}



//----END--------------------------------------------------------------------


for date emulation......

//in Sqlite3upp.cpp -------------------------------------------------
in....
void Sqlite3Connection::BindParam(int i, const Value& r) {
....
Change
		case DATE_V: {
				Date d = r;
				String p = Format("%02d-%02d-%04d", d.month, d.day, d.year);
				sqlite3_bind_text(current_stmt,i,p,p.GetLength(),SQLITE_TRANSIENT);
			}
			break;

with
		case DATE_V: {
				Date d = r;
                                String p = Format("%04d-%02d-%02d", d.year, d.month, d.day, );
				sqlite3_bind_text(current_stmt,i,p,p.GetLength(),SQLITE_TRANSIENT);
			}
			break;

------------------------------------------------------------------
in.....
 bool Sqlite3Connection::Execute() 
....
change
switch (sqlite3_column_type(current_stmt,i)) {

with
String coltype = sqlite3_column_decltype(current_stmt,i);
switch (sqlite3_column_type(current_stmt,i)) {


change
				case SQLITE_TEXT:
					field.type = WSTRING_V;
					break;
with
				case SQLITE_TEXT:
                                        if (coltype == "date") field.type = DATE_V;
					else field.type = WSTRING_V;
					break;

---------------------------------------------------------------
in.....
 void Sqlite3Connection::GetColumn(int i, Ref f) const {
.....
change

	switch (sqlite3_column_type(current_stmt,i)) {

with
	String coltype = sqlite3_column_decltype(current_stmt,i);
	String sdate;
        switch (sqlite3_column_type(current_stmt,i)) {

change
		case SQLITE_TEXT:
			f = Value(WString((const wchar*)sqlite3_column_text16(current_stmt,i)));
			break;

with
		case SQLITE_TEXT:
                        if (coltype == "date"){
                           sdate = (const char*)sqlite3_column_text(current_stmt,i);
                           f = Value(Date(atoi(sdate.Mid(0,4)),atoi(sdate.Mid(5,2)),atoi(sdate.Mid(8,2))));
                        }else{                         
			f = Value(WString((const wchar*)sqlite3_column_text16(current_stmt,i)));
			}
                        break;

Change
		case SQLITE_NULL:
			f = Null;
			break;

with
		case SQLITE_NULL:
			if (coltype=="date")
                           f = (Date)Null;
			else
                           f = Null;
                        break;

-END---------------------------------------------------------
