Exemplo n.º 1
0
	def getRowsByValue(self, limitByKey=True, **kwargs):

		cur = kwargs.pop("cur", None)

		if limitByKey and self.tableKey:
			kwargs["sourceSite"] = self.tableKey


		where = self.sqlBuildConditional(**kwargs)

		wantCols = (
				self.table.dbid,
				self.table.dlstate,
				self.table.sourceurl,
				self.table.retreivaltime,
				self.table.lastupdate,
				self.table.sourceid,
				self.table.seriesname,
				self.table.filename,
				self.table.originname,
				self.table.downloadpath,
				self.table.flags,
				self.table.tags,
				self.table.note
				)

		query = self.table.select(*wantCols, order_by=sql.Desc(self.table.retreivaltime), where=where)

		query, quargs = tuple(query)

		if self.QUERY_DEBUG:
			print("Query = ", query)
			print("args = ", quargs)

		if cur is not None:
			cur.execute(query, quargs)
			rets = cur.fetchall()
		else:
			with self.transaction(commit=False) as cur:
				cur.execute(query, quargs)
				rets = cur.fetchall()


		retL = []
		for row in rets:

			keys = ["dbId", "dlState", "sourceUrl", "retreivalTime", "lastUpdate", "sourceId", "seriesName", "fileName", "originName", "downloadPath", "flags", "tags", "note"]
			retL.append(dict(zip(keys, row)))
		return retL
Exemplo n.º 2
0
    def getRowsByValue(self, limitByKey=True, cursor=None, **kwargs):
        if limitByKey and self.tableKey:
            kwargs["src"] = self.tableKey

        where = self.sqlBuildConditional(**kwargs)

        wantCols = (self.table.dbid, self.table.src, self.table.dlstate,
                    self.table.url, self.table.title, self.table.series,
                    self.table.contents, self.table.istext, self.table.fhash,
                    self.table.mimetype, self.table.fspath)

        query = self.table.select(*wantCols,
                                  order_by=sql.Desc(self.table.dbid),
                                  where=where)

        query, quargs = tuple(query)

        if self.QUERY_DEBUG:
            print("Query = ", query)
            print("args = ", quargs)

        if cursor:

            cursor.execute(query, quargs)
            rets = cursor.fetchall()
        else:
            with self.transaction() as cur:
                #wrap queryies in transactions so we don't have hanging db handles.
                cur.execute(query, quargs)
                rets = cur.fetchall()

        retL = []
        for row in rets:

            keys = [
                'dbid', 'src', 'dlstate', 'url', 'title', 'series', 'contents',
                'istext', 'fhash', 'mimetype', 'fspath'
            ]
            retL.append(dict(zip(keys, row)))
        return retL