All Downloads are FREE. Search and download functionalities are using the official Maven repository.

online.sanen.unabo.sql.infomation.SQLiteInfomation Maven / Gradle / Ivy

The newest version!
package online.sanen.unabo.sql.infomation;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

import online.sanen.unabo.api.Bootstrap;
import online.sanen.unabo.api.structure.Column;
import online.sanen.unabo.api.structure.DataInformation;

/**
 * 
 * @author LazyToShow
 * Date: 2018/06/12
 * Time: 09:17
 */
public class SQLiteInfomation extends DataInformation{
	
	public SQLiteInfomation(Bootstrap bootstrap) {
		super(bootstrap);
	}

	@Override
	public List getDatabases() {
		
		return Arrays.asList("main");
	}

	@Override
	public List getTablesAndViews() {
		
		String sql = "SELECT name FROM sqlite_master where name<>'sqlite_sequence'";
		return bootstrap.createSQL(sql).list();
	}

	@Override
	public List beforeGetColumns(String tableName) {
		String sql = "PRAGMA table_info('"+tableName+"')";
		List> maps = bootstrap.createSQL(sql).maps();
		List columns = new ArrayList(maps.size());

		maps.forEach(map -> {
			Column column = new Column();
			column.setName(map.get("name").toString());
			column.setType(map.get("type").toString());
			column.setLength(column.getType());
			column.setIsnullable(Integer.parseInt(map.get("notnull").toString())==0);
			column.setDefaultval(map.get("dflt_value"));
			column.setIspk(Integer.parseInt(map.get("pk").toString())==1);
			columns.add(column);
		});

		return columns;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy