Page Split :ZT

SQL存储过程操作数据库对象
博客展示了一个SQL存储过程sp_script,用于操作数据库对象。通过一系列SQL语句,连接到服务器,获取数据库信息,根据对象名获取对应表,并对表进行脚本操作,最后输出脚本内容。
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

 

 

ALTER    procedure sp_script
        @objectname varchar(50)
as
declare @databasename varchar(50)

set @databasename = DB_NAME(DB_ID())

declare        @str varchar(4000)


DECLARE @object int
declare @objectdatabase int
DECLARE @hr int
DECLARE @src varchar(255), @desc varchar(255)
DECLARE @DataBaseCount int, @Current int, @DataBase int

declare @table int, @tables int

EXEC @hr = sp_OACreate 'SQLDMO.SQLServer', @object OUT
IF @hr <> 0
BEGIN
     EXEC sp_OAGetErrorInfo @object, @src OUT, @desc OUT
   SELECT hr=convert(varbinary(4),@hr), Source=@src, Description=@desc
    RETURN
END

EXEC @hr = sp_OAMethod @object, 'Connect', NULL, @@servername,
    'sa', ''

IF @hr <> 0
BEGIN
   EXEC sp_OAGetErrorInfo @object
    RETURN
END

EXEC @hr = sp_OAGetProperty @object, 'Databases', @objectdatabase output

IF @hr <> 0
BEGIN
   EXEC sp_OAGetErrorInfo @objectdatabase, @src OUT, @desc OUT
   SELECT hr=convert(varbinary(4),@hr), Source=@src, Description=@desc
    RETURN
END

 

EXEC @hr = sp_OAGetProperty @objectdatabase, 'count', @DataBaseCount output
IF @hr <> 0
BEGIN
   EXEC sp_OAGetErrorInfo @objectdatabase, @src OUT, @desc OUT
   SELECT hr=convert(varbinary(4),@hr), Source=@src, Description=@desc
    RETURN
END


set @Current = 1
loop1:

  EXEC @hr = sp_OAMethod @objectdatabase, 'Item', @Database output, @databasename

  IF @hr <> 0
  BEGIN
    EXEC sp_OAGetErrorInfo @objectdatabase
     RETURN
  END


EXEC @hr = sp_OAMethod @Database, 'GetObjectByName', @table output, @objectname

  IF @hr <> 0
  BEGIN
    EXEC sp_OAGetErrorInfo @Database
     RETURN
  END

Exec @hr = sp_OAMethod @table, 'Script', @str output, 5
  IF @hr <> 0
  BEGIN
    EXEC sp_OAGetErrorInfo @table
     RETURN
  END


print @str

 

 


GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

 

<template> <view style="background-color: #F7F7F7;padding-top: 10px;min-height: 97vh;padding-bottom: 100rpx;"> <view class="clxq-content" @click="btnclxq(item)" v-for="item in List"> <view class="clxq-content-left"> <image class="clxq-content-left-image" v-if="item.clzp" :src="item.clzp"></image> <image class="clxq-content-left-image" v-else src="@/static/clzp.png"></image> </view> <view class="clxq-content-right"> <view class="clxq-content-right-text" style="font-weight: 700;">{{item.cph}}</view> <view class="clxq-content-right-text"> <text>姓名:</text> <text>{{item.sjxm}}</text> </view> <!-- <view class="clxq-content-right-text"> <text>联系方式:</text> <text>{{item.lxfs}}</text> </view> --> <view class="clxq-content-right-text"> <text>承运类型:</text> <text>{{item._cylx}}</text> </view> </view> <view class='clxq-content-btn'> <text @click.stop="btncljb(item)" v-if="item.state =='绑定'" class="clxq-content-btn-stop">解绑</text> <text @click.stop="btnclbd(item)" v-if="item.state =='解绑'" class="clxq-content-btn-start">绑定</text> </view> </view> <image v-if='List.length ==0' src="@/static/kong.png" class="kongceng" mode=""></image> <view class="clxq-add-btn" @click="addBtn">添加车辆</view> <view class="mengbans" v-if="cphshowN"> <view style='width:100%;height: 100%;display: flex;justify-content: center;align-items: center;'> <view style="background-color: #fff; width:280px;height: 170px;border-radius: 8px;position: relative;"> <view style="display: flex;margin-top: 50px;padding:0 10px">车牌号:<input type="text" style="border-bottom: 1px solid #CCC;" placeholder="请输入车牌号" v-model="cph" @blur="bindcph" /> </view> <view style="margin-top:15px" v-if='rylx == "2ECND12H"'> <text style='float:left;padding-left:10px;font-size:14px'>绑定身份:</text> <radio-group @change="Change"> <label class="mokuai-row" style="margin-left: 15px;"> <radio value="2ECND12F" checked style='font-size:14px'>司机</radio> <radio value="2ECND12G" style="margin-left: 15px;font-size:14px">押运员</radio> </label> </radio-group> </view> <view style="position: absolute;bottom: 0;height: 40px;border-top: 1px solid #ccc;width: 100%;line-height: 40px;"> <view @click="btnokN" style="display: inline-block;width: 50%;height: 100%;border-radius: 0 0 0 8px;background-color: #00CD9F;color: #fff;text-align: center;"> 确定</view> <view @click="quxiaoN" style="display: inline-block;width: 50%;height: 100%;text-align: center;">取消</view> </view> </view> </view> </view> </view> </template> <script> import { mapState, mapMutations } from 'vuex' import req from '@/utils/request.js'; import utils from '@/utils/util.js'; export default { data() { return { cphshowN:false, cph:"", rylx: "", bdlx:"", inputcph:"", page:1, rows:10, List:[], cphjy: false, hasMore: true, // 控制是否还有更多数据 loading: false // 防止重复加载 } }, computed: { ...mapState('m_user', ['openId', 'needLogin', 'hyxx', 'zcxx']), /* qyid() { return this.hyxx.qyid }, */ }, onReachBottom() { if (!this.hasMore || this.loading) { uni.showToast({ title: '没有更多数据了', icon: 'none' }); return; } this.page += 1; this.getList(); }, onShow() { this.List = [] this.getList() this.rylx = this.hyxx.rylx this.bdlx = this.hyxx.rylx }, methods: { addBtn(){ this.cph = '' this.cphshowN = true }, //人员类型修改 Change(e) { /* console.log(e.detail.value) */ this.bdlx = e.detail.value }, //启用车辆 btnclbd(item){ this.cphjy = true this.cphshowN = true this.cph = item.cph }, //停用车辆 btncljb(item){ var my = this if(item.clid){ uni.showModal({ title: '提示', content: '确定要解绑当前车辆吗?', success: (res) => { if(res.confirm){ this.$vsportal("Sjzc.cljb", {clid:item.clid,hyryid:this.hyxx.id,bdlx:this.bdlx}).then(function(res) { if(res.data.zt == 'FAIL'){ uni.$showMsg("有未完成的订单,暂时不允许解绑"); }else{ uni.$showMsg("解绑成功"); my.List = [] my.getList() } }); } } }) } }, //车辆详情 btnclxq(item){ if(item.state =='解绑'){ uni.$showMsg("暂无查看该车辆的权限"); }else{ uni.navigateTo({ url: '/pagesFen/wode/clxq-new?clid=' + item.clid }) } }, zpurl(zp) { let zpurl = new Array(zp.length); for (let i = 0; i < zp.length; i++) { zpurl[i] = req.imageUrl(zp[i]); } return zpurl; }, getList() { var my = this; if (my.loading) return; my.loading = true; my.$vsportal('Sjzc.useclList', { hyryid: my.hyxx.id, cph: my.inputcph, page: my.page, rows: my.rows }).then(function(res) { if (res.status) { if (res.data.length < my.rows) { my.hasMore = false; // 如果返回数据少于一页数量,说明是最后一页 } res.data.forEach(item => { let clzpArr = [] if (item.clzp) { let clzp = item.clzp.split(","); clzpArr.push(clzp[0]) item.clzp = my.zpurl(clzpArr); } }); my.List = [...my.List, ...res.data]; // 合并新数据 } my.loading = false; }).catch(() => { my.loading = false; }); }, btnokN() { var my = this if (my.cphjy) { my.$vsportal('Sjzc.clbdzt', { cph: my.cph, bdlx: my.bdlx }).then(function(res) { if (JSON.stringify(res.data) === '{}') { uni.navigateTo({ url: '/pagesFen/zhuce/clrz-new?hyryid=' + my.hyxx.id + '&cph=' + my.cph }); my.cphshowN = false } else { if (res.data.name && res.data.lxfs) { var phone = res.data.lxfs var content = '该车辆已绑定司机' + res.data.name + '是否联系' + res.data.lxfs + '解绑?' uni.showModal({ title: '提示', content: content, showCancel: true, success: (res) => { if (res.confirm) { uni.makePhoneCall({ phoneNumber: phone, success: function() { console.log('拨打电话成功'); }, fail: function() { console.log('拨打电话失败'); } }) } }, fail: (err) => { } }); } else { my.$vsportal('Sjzc.clbd', { clid: res.data.id, clid_y:my.hyxx.clid, ryid: my.hyxx.id, bdlx: my.bdlx, clzp:res.data.clzp ? res.data.clzp : '', sjxm:my.hyxx.name, lxfs:my.hyxx.lxfs, cylx:my.hyxx.cylx, cph:res.data.cph, }).then(function(res) { uni.$showMsg("车辆绑定成功"); my.cphshowN = false my.List = [] my.getList() }) } } }); //my.cphshow = false } }, quxiaoN() { this.cphshowN = false }, CphYz: function(val) { // var reg = // /(^[\u4E00-\u9FA5]{1}[A-Z0-9]{6}$)|(^[A-Z]{2}[A-Z0-9]{2}[A-Z0-9\u4E00-\u9FA5]{1}[A-Z0-9]{4}$)|(^[\u4E00-\u9FA5]{1}[A-Z0-9]{5}[挂学警军港澳]{1}$)|(^[A-Z]{2}[0-9]{5}$)|(^(08|38){1}[A-Z0-9]{4}[A-Z0-9挂学警军港澳]{1}$)/; var reg = /^(([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-Z](([0-9]{5}[DF])|([DF]([A-HJ-NP-Z0-9])[0-9]{4})))|([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-Z][A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9挂学警港澳使领]))$/ return reg.test(val); }, bindcph: function(e) { // let cph1 = '' var my = this; var cph = my.cph; // setTimeout(function() { let len = cph.length if (len !== 7 && len !== 8) { uni.$showMsg("请输入完整的车牌号!"); my.cphjy = false } else { if (my.CphYz(cph)) { my.cphjy = true } else { my.cph = cph; my.flag = false my.cphjy = false uni.$showMsg("请检查车牌号是否正确!"); } } // }, 5000); }, } } </script> <style lang="scss"> .clxq-content{ background-color: #fff; border-radius: 8px; display: flex; padding: 10px; margin: 10px; justify-content: space-between; margin-bottom: 10px; } .clxq-content-left{ background-color:#00CD9F; width: 220rpx; height: 180rpx; } .clxq-content-left-image{ width: 100%; height: 100%; } .clxq-content-right{ margin-left: 5px; } .clxq-content-right-text{ font-size: 14px; line-height: 50rpx; text:nth-child(1){ color:#B8B7B8 } :nth-child(2){ color: #333; } } .clxq-add-btn{ background-color: #00CD9F; position: fixed; bottom: 30px; left:10px; width: 95%; height: 80rpx; color:#fff; border-radius: 8px; font-size: 16px; display: flex; align-items: center; justify-content: center; } .clxq-content-btn{ display: flex; flex-direction: column; justify-content: center; align-items: center; text{ width: 110rpx; height: 60rpx; color:#fff; border-radius: 8px; text-align: center; line-height: 60rpx; } .clxq-content-btn-stop{ background-color: #00CD9F; } .clxq-content-btn-start{ background-color: #B8B7B8; } } .mengbans { width: 100%; height: 100vh; position: fixed; top: 0; background-color: rgba(0, 0, 0, 0.4); z-index: 999; } </style> 加懒加载数据,加载到最后一页了就不允许再请求数据了,提示暂无数据就可以
最新发布
08-27
-*- coding: utf-8 -*- """ @file: ledger @author: maxiaolong01 @date: 2025/7/7 11:45 """ import io from typing import List import numpy as np import pandas as pd from fastapi import APIRouter, Query, File, UploadFile, HTTPException, status from tortoise.exceptions import ValidationError from tortoise.expressions import Q from app.api.v1.utils import insert_log from app.controllers import user_controller from app.controllers.interlockledger import interlockledger_controller from app.controllers.zentao.zt_equip import ztequip_controller from app.core.ctx import CTX_USER_ID from app.models.interlock import InterLockLedger from app.models.system import LogType, LogDetailType from app.schemas.base import SuccessExtra, Success from app.schemas.interlockledger import InterLockLedgerSearch, InterLockLedgerCreate, InterLockLedgerUpdate from app.utils.cdg_tool import CdgClient from app.utils.cdg_tool import CdgClient router = APIRouter() @router.post("/ledgers/all", summary="查看互锁台账列表") async def _(obj_in: InterLockLedgerSearch): ids = obj_in.__pydantic_extra__.get("ids") q = Q() if ids: q &= Q(Q(id__in=ids)) if obj_in.alarm_name: q &= Q(alarm_name__contains=obj_in.alarm_name) if obj_in.product: q &= Q(product=obj_in.product) if obj_in.lock_type: q &= Q(lock_type=obj_in.lock_type) if obj_in.module_name: q &= Q(module_name__contains=obj_in.module_name) if obj_in.alarm_level: q &= Q(alarm_level=obj_in.alarm_level) if obj_in.dept_name: q &= Q(dept_name__contains=obj_in.dept_name) if obj_in.module_type: q &= Q(module_type=obj_in.module_type) user_id = CTX_USER_ID.get() user_obj = await user_controller.get(id=user_id) total, api_objs = await interlockledger_controller.list(page=obj_in.current, page_size=obj_in.size, search=q, order=obj_in.order_list or ["-id"]) records = [] for obj in api_objs: data = await obj.to_dict(exclude_fields=[]) records.append(data) data = {"records": records} await insert_log(log_type=LogType.UserLog, log_detail_type=LogDetailType.InterLockLedgerList, by_user_id=user_obj.id) return SuccessExtra(data=data, total=total, current=obj_in.current, size=obj_in.size) @router.post(path='/ledgers', summary='创建互锁台账记录') async def _(obj_in: InterLockLedgerCreate): # 互锁台账记录创建接口 new_ledger = await interlockledger_controller.create(obj_in=obj_in) print(obj_in) await insert_log(log_type=LogType.UserLog, log_detail_type=LogDetailType.InterLockLedgerCreate, by_user_id=0) return Success(msg='Create Successfully', data={"create_id": new_ledger.id}) @router.patch(path='/ledgers/{ledger_id}', summary='更新互锁台账记录') async def _(ledger_id: int, obj_in: InterLockLedgerUpdate): await interlockledger_controller.update(id=ledger_id, obj_in=obj_in) await insert_log(log_type=LogType.UserLog, log_detail_type=LogDetailType.InterLockLedgerUpdate, by_user_id=0) return Success(msg="Updated Successfully", data={"updated_id": ledger_id}) @router.delete(path='/ledgers/{ledger_id}', summary='删除互锁台账记录') async def _(ledger_id: int): await interlockledger_controller.remove(id=ledger_id) await insert_log(log_type=LogType.UserLog, log_detail_type=LogDetailType.InterLockLedgerDelete, by_user_id=0) return Success(msg="Deleted Successfully", data={"deleted_id": ledger_id}) @router.delete(path='/ledgers', description='批量删除互锁台账记录') async def _(ids: str = Query(..., description='互锁台账ID列表,用逗号隔开')): ledger_ids = ids.split(",") deleted_ids = [] print('删除互锁台账id记录') for ledger_id in ledger_ids: ledger_obj = await InterLockLedger.get(id=int(ledger_id)) await ledger_obj.delete() deleted_ids.append(int(ledger_id)) await insert_log(log_type=LogType.UserLog, log_detail_type=LogDetailType.InterLockLedgerBatchDelete, by_user_id=0) return Success(msg="Deleted Successfully", data={"deleted_ids": deleted_ids}) 标记删除使is_del字段=1
08-23
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值