本文整理匯總了Python中MySQL.MySQL.getInsertId方法的典型用法代碼示例。如果您正苦於以下問題:Python MySQL.getInsertId方法的具體用法?Python MySQL.getInsertId怎麽用?Python MySQL.getInsertId使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類MySQL.MySQL
的用法示例。
在下文中一共展示了MySQL.getInsertId方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: createShortUrl
# 需要導入模塊: from MySQL import MySQL [as 別名]
# 或者: from MySQL.MySQL import getInsertId [as 別名]
def createShortUrl(url):
urlId = 0
db = MySQL()
urlhash = Utils.MD5(url)
# first find
urlInstance = db.get(r"SELECT * FROM `short_urls` WHERE `hash`=%s", urlhash)
if urlInstance:
urlId = urlInstance['id']
# create if don't found
if urlId == 0:
result = db.save(r"INSERT INTO `short_urls` (`hash`, `url`) VALUES (%s,%s)", (urlhash, url))
urlId = db.getInsertId()
db.end()
return __short_url_prefix + NumberCodec.encode(urlId)
示例2: video_create
# 需要導入模塊: from MySQL import MySQL [as 別名]
# 或者: from MySQL.MySQL import getInsertId [as 別名]
def video_create(data):
"""
設置視頻信息
方法:
video_create
參數:
UserKey[string] –用戶登錄後的會話ID。
UploadId[string] – 分配的上傳會話ID
Title[string] – 視頻標題
Author[string] – 分享者/創作者名稱
CreateTime[date] – 創作日期
Category[string] – 視頻分類
Describe[string] – 視頻描述
Tag[string] – 視頻標簽,標簽內容有半角“,”(逗號)分割
AddrStr[string] - 視頻位置信息
Longitude[float] - 視頻位置 - 經度
Latitude[float] - 視頻位置 - 緯度
返回值:
VID[string] – 視頻ID
"""
userId = UserService.user_id(data['UserKey'])
fileName = "%s/%s" % (uploadDirectory, data['UploadId'])
db = MySQL()
newId = Utils.UUID()
media = MediaProbe(fileName)
# media.createTime()
result = db.save("""INSERT INTO `video` (`id`, `upload_id`, `owner_id`, `duration`, `video_width`, `video_height`, `video_bitrate`, `title`, `author`, `create_date`, `category`, `describe`, `tag`, `lbs_addr`, `lbs_lon`, `lbs_lat`)
VALUES (%s,%s,%s,%s,%s, %s,%s,%s,%s,%s, %s,%s,%s,%s,%s,%s)""",
(newId, data['UploadId'], userId, media.duration(), media.videoWidth(), media.videoHeight(), media.videoBitrate(),
data.get('Title', ''),
data.get('Author', ''),
data.get('CreateTime', media.createTime()),
data.get('Category', ''),
data.get('Describe', ''),
data.get('Tag', ''),
data.get('AddrStr', None),
data.get('Longitude', None),
data.get('Latitude', None)))
db.end()
# 截圖
destFileName = "%s/%s.jpg" % (videoDirectory, newId)
Transcoder.VideoPoster(fileName, destFileName)
# post transcode task
# 原清晰度
if media.videoCodec() == 'h264' and media.audioCodec() == 'aac' :
result = db.save("""INSERT INTO `video_transcode` (`video_id`, `file_name`, `video_width`, `video_height`, `video_bitrate`, `video_codec`, `audio_channels`, `audio_bitrate`, `audio_codec`)
VALUES (%s,%s,%s,%s,%s, %s,%s,%s,%s)""",
(newId, newId + '.mp4',
media.videoWidth(),
media.videoHeight(),
media.videoBitrate(),
'copy',
media.audioChannels(),
media.audioBitrate(),
'copy'))
taskId = db.getInsertId()
db.end()
else:
result = db.save("""INSERT INTO `video_transcode` (`video_id`, `file_name`, `video_width`, `video_height`, `video_bitrate`, `video_codec`, `audio_channels`, `audio_bitrate`, `audio_codec`)
VALUES (%s,%s,%s,%s,%s, %s,%s,%s,%s)""",
(newId, newId + '.mp4',
media.videoWidth(),
media.videoHeight(),
media.videoBitrate(),
TranscodeTemplates.HD['video_codec'],
media.audioChannels(),
media.audioBitrate(),
TranscodeTemplates.HD['audio_codec'] ))
taskId = db.getInsertId()
db.end()
# 高清
if media.supportHD() and not media.DefinitionIsHD():
result = db.save("""INSERT INTO `video_transcode` (`video_id`, `file_name`, `video_width`, `video_height`, `video_bitrate`, `video_codec`, `audio_channels`, `audio_bitrate`, `audio_codec`)
VALUES (%s,%s,%s,%s,%s, %s,%s,%s,%s)""",
(newId, newId + '_hd.mp4',
int(TranscodeTemplates.HD['video_width']),
int(TranscodeTemplates.HD['video_width']) / media.videoAspect(),
TranscodeTemplates.HD['video_bitrate'],
TranscodeTemplates.HD['video_codec'],
TranscodeTemplates.HD['audio_channel'],
TranscodeTemplates.HD['audio_bitrate'],
TranscodeTemplates.HD['audio_codec'] ))
taskId = db.getInsertId()
db.end()
# 標清
if media.supportSD() and not media.DefinitionIsSD():
result = db.save("""INSERT INTO `video_transcode` (`video_id`, `file_name`, `video_width`, `video_height`, `video_bitrate`, `video_codec`, `audio_channels`, `audio_bitrate`, `audio_codec`)
VALUES (%s,%s,%s,%s,%s, %s,%s,%s,%s)""",
(newId, newId + '_sd.mp4',
int(TranscodeTemplates.SD['video_width']),
int(TranscodeTemplates.SD['video_width']) / media.videoAspect(),
TranscodeTemplates.SD['video_bitrate'],
#.........這裏部分代碼省略.........
示例3: MediaProbe
# 需要導入模塊: from MySQL import MySQL [as 別名]
# 或者: from MySQL.MySQL import getInsertId [as 別名]
newId = video['id']
media = MediaProbe(uploadFileName)
# 原清晰度
if media.videoCodec() == 'h264' and media.audioCodec() == 'aac' :
result = db.save("""INSERT INTO `video_transcode` (`video_id`, `file_name`, `video_width`, `video_height`, `video_bitrate`, `video_codec`, `audio_channels`, `audio_bitrate`, `audio_codec`)
VALUES (%s,%s,%s,%s,%s, %s,%s,%s,%s)""",
(newId, newId + '.mp4',
media.videoWidth(),
media.videoHeight(),
media.videoBitrate(),
'copy',
media.audioChannels(),
media.audioBitrate(),
'copy'))
taskId = db.getInsertId()
db.end()
else:
result = db.save("""INSERT INTO `video_transcode` (`video_id`, `file_name`, `video_width`, `video_height`, `video_bitrate`, `video_codec`, `audio_channels`, `audio_bitrate`, `audio_codec`)
VALUES (%s,%s,%s,%s,%s, %s,%s,%s,%s)""",
(newId, newId + '.mp4',
media.videoWidth(),
media.videoHeight(),
media.videoBitrate(),
TranscodeTemplates.HD['video_codec'],
media.audioChannels(),
media.audioBitrate(),
TranscodeTemplates.HD['audio_codec'] ))
taskId = db.getInsertId()
db.end()