Ejemplo n.º 1
0
	def checkMultiSqlCache(self):
		if "```" in self.multiSqlCache:
			self.multiSqlCache = self.multiSqlCache[:-3]
			sqls = self.multiSqlCache.split(";")
			errors = {}
			results = {}
			for i in range(len(sqls)):
				sql = sqls[i]
				if not sql.strip():
					continue
				try:
					result = self.execSql(sql)
					results[i] = []
					results[i].append(result.column_names)
					for j in result:
						results[i].append(j)
				except Exception as e:
					errors[i] = e
			for i,result in results.items():
				if not result[0]:
					print(f"Query #{i}: Successfuly executed, No result returned (Empty Set)")
					continue
				self.displayFormattedResult(result)
				print("")
			for i, error in errors.items():
				log(f"Query #{i}: {error}",isError=True)
			self.flags["mode"] = "normal"
			self.multiSqlCache = ""
Ejemplo n.º 2
0
	def useDb(self,name):
		if not name.strip():
			log("Invalid Database Name.",isError=True)
		name = name.split(" ")[0]
		self.execSql(f"USE {name}")
		self.meta["dbName"] = name
		self.flags["layer"] = 1
Ejemplo n.º 3
0
def lt(client, args):
    if not args:
        log("MKDB takes in 1 argument: Database Name", isError=True)
    try:
        client.execSql(f"CREATE DATABASE {args[0]}")
    except Exception as e:
        log(e, isError=True)
Ejemplo n.º 4
0
	def execCmd(self,cmd):
		if not cmd.strip():
			return
		parts = cmd.split(" ")
		if parts[0].lower() in COMMANDS:
			COMMANDS[parts[0].lower()](self,parts[1:])
		else:
			log(f"Unknown Command: {parts[0]}", isError=True)
Ejemplo n.º 5
0
def lt(client, args):
    try:
        result = client.fetchTables()
        outputs = ""
        for i in result:
            outputs += f"{i}    "
        print(parse(outputs))
    except Exception as e:
        log(e, isError=True)
Ejemplo n.º 6
0
	def checkSqlCache(self):
		if ";" in self.sqlCache:
			try:
				result = self.execSql(self.sqlCache)
				formatted = self.getFormatFromCursor(result)
				self.displayFormattedResult(formatted)
			except Exception as e:
				log(e, isError=True)
			self.flags["mode"] = "normal"
			self.sqlCache = ""
Ejemplo n.º 7
0
def use(client, args):
    if not args:
        log("Please specify the name of the database.", isError=True)
        return
    try:
        client.execSql(f"USE {args[0]}")
        client.meta["dbName"] = args[0]
        client.flags["layer"] = 1
    except Exception as e:
        log(e, isError=True)
Ejemplo n.º 8
0
	def execute(self):
		while True:
			if self.flags["welcome"]:
				print("frSqlTools v1.0, developed by Frankium, impelemnted using fr-sh.")
				self.flags["welcome"] = False
				continue
			if not self.db:
				try:
					host, user, password = input(parse("Host §y>>§0 ")), input(parse("Username §y>>§0 ")), getpass.getpass(parse("Password §y>>§0 "))
					if not host.strip():
						log("Host cannot be empty.",isError=True)
						continue
					self.connect(host.strip(),user.strip(),password)
				except Exception as e:
					log(e,isError=True)
				except KeyboardInterrupt as k:
					log("Aborted",front="\n")
					self.stop()
			else:
				self.setCarrot(self.commandCarrot)
				k = GetKeyPress.listen()
				if k in Events.KEYPRESS_EVENTS:
					Events.KEYPRESS_EVENTS[k](self)
				elif (k.isprintable()) and (len(k) == 1):
					self.command = self.command[:self.commandCarrot] + k + self.command[self.commandCarrot:]
					self.commandCarrot += 1
			if self.flags["interpretBreak"]:
				break
Ejemplo n.º 9
0
def lt(client, args):
    if not args:
        log("RMDB takes in 1 argument: Database Name", isError=True)
    try:
        while True:
            sys.stdout.write(
                f"Are you sure to REMOVE DATABASE `{args[0]}`? [y/n]")
            sys.stdout.flush()
            key = listen()
            if key in ("y", "Y"):
                print("")
                break
            if key in ("n", "N"):
                print("")
                return
            log(f"Unknown option: {key}", front="\n", isError=True)
        client.execSql(f"DROP DATABASE {args[0]}")
    except Exception as e:
        log(e, isError=True)
Ejemplo n.º 10
0
	def connect(self,host="",user="",password=""):
		self.db = mysql.connector.connect(host=host, user=user, password=password)
		self.meta = {"host":host, "user":user, "dbName": self.meta["dbName"]}
		log(f"Connected to {host} as {user}.")