/** 
 * Project    : KANT (LMT)
 * Source Name: Version.java
 * Copyright  : Copyright (c) LTI, Carnegie Mellon University
 * Description: Class for user
 * @version     1.0 (created by jko - 10/01/01)
 **/

package lmt;

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

public class Version {
  String version;
	
  /** get the version from the database
   * @return string representing version number
   **/	
  public static String getVersion(SQLConnection con) {
    String version = "";
		
    if ( con == null || !con.connect()) {
      Debug.debug("-- getVersion: connnection is null or not connected - " + con);
      return version;
    }
			
    // check username and password
    String sql = "SELECT UNIQUE(VERSION) FROM LMT_VERSION_ENTRIES";
    try {
      SQLConnection.Result r = con.query(sql);
      if (r!=null && r.hasData()) {
	if (r.rs.getString(1) != null)
	  version = r.rs.getString(1);
      }
      if (r!=null) r.close();
    } catch (SQLException E) {
      Debug.debug("login SQLException: " + E.getMessage());
    }	

    return version;
  }
	
  /** set the version from the database
   * @return boolean representing the result of update
   **/	
  public static boolean setVersion(SQLConnection con, String version) {
    if ( con == null || !con.connect()) {
      Debug.debug("-- setVersion: connnection is null or not connected - " + con);
      return false;
    }
			
    // check username and password
    String sql = "UPDATE LMT_VERSION_ENTRIES SET VERSION = '" + version +"'";
    int ret = con.updateQuery(sql);
    return (ret != Constants.ERROR);
  }
}	
