Metadata-Version: 2.3
Name: pylhb4mssql4odbc
Version: 1.0.0
Summary: Mr.Lee's MSSQL With ODBC Helpers
Author: SoftGod4MrLi
Author-email: SoftGod4MrLi <596928288@qq.com>
License: Non-Commercial Use License
         
         Copyright (c) 2025 Mr.Lee
         
         Permission is hereby granted, free of charge, to any person obtaining a copy
         of this software and associated documentation files (the "Software"), to deal
         in the Software for non-commercial purposes only, including without limitation
         the rights to use, copy, modify, merge, publish, distribute, sublicense,
         and/or sell copies of the Software, subject to the following conditions:
         
         1. The above copyright notice and this permission notice shall be included in all
         copies or substantial portions of the Software.
         
         2. Commercial use of the Software is expressly prohibited without prior written
         permission from the copyright holder. For purposes of this license, commercial
         use means any use of the Software that is intended for or directed toward
         commercial advantage or monetary compensation.
         
         THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
         IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
         FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
         AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
         LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
         OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
         SOFTWARE.
Requires-Dist: pyodbc>=5.3.0
Requires-Python: >=3.12
Project-URL: Homepage, https://github.com/SoftGod4MrLi/pylhb4mssql4odbc
Project-URL: Documentation, https://github.com/SoftGod4MrLi/pylhb4mssql4odbc
Project-URL: Repository, https://github.com/SoftGod4MrLi/pylhb4mssql4odbc
Project-URL: Issues, https://github.com/SoftGod4MrLi/pylhb4mssql4odbc/issues
Description-Content-Type: text/markdown

# pylhb4mssql4odbc

[![PyPI version](https://img.shields.io/pypi/v/pylhb4mssql4odbc.svg)](https://pypi.org/project/pylhb4mssql4odbc/)
[![GitHub stars](https://img.shields.io/github/stars/SoftGod4MrLi/pylhb4mssql4odbc?style=flat&logo=github)](https://github.com/SoftGod4MrLi/pylhb4mssql4odbc)
[![GitHub license](https://img.shields.io/github/license/SoftGod4MrLi/pylhb4mssql4odbc?style=flat)](https://github.com/SoftGod4MrLi/pylhb4mssql4odbc/blob/main/LICENSE)
![GitHub repo size](https://img.shields.io/github/repo-size/SoftGod4MrLi/pylhb4mssql4odbc?style=flat)
[![GitHub forks](https://img.shields.io/github/forks/SoftGod4MrLi/pylhb4mssql4odbc?style=flat&logo=github)](https://github.com/SoftGod4MrLi/pylhb4mssql4odbc)

pylhb4mssql4odbc 是我在工作过程中陆续整理的一个 Python mssql with odbc 工具包，里面就放在一个关于mssql操作的类及相关函数。与其说是一个正式的开源项目，不如说是我自己的“代码杂物间”——只不过把它打包了一下，方便在不同项目之间复用。

> 由于是个人使用为主，很多设计可能带着比较强的个人习惯，也未必是最优解。如果您发现了问题或有更好的建议，非常欢迎指正。

## 安装

```
pip install pylhb4mssql4odbc
```

## 🌺mypymssql模块

通过odbc访问Microsoft SQL Server。

注意：

> ODBC Driver 17 for SQL Server下载：  
> https://learn.microsoft.com/zh-cn/sql/connect/odbc/download-odbc-driver-for-sql-server?view=sql-server-ver16  
> 注意，如果是ODBC Driver 18 for SQL Server，那实例化时记得传driver.

使用示例：

```
from pylhb4mssql4odbc.mypymssql import MyMSSQL

if __name__ == "__main__":
    server="127.0.0.1"
    user="sa"
    password="fpsoft@123"
    database="MyCustomer"
    # 实例化
    #mssql=MyMSSQL(server=server,database=database)
    mssql=MyMSSQL(server=server,user=user,password=password,database=database)
    # 连接数据库
    (successed,msg)=mssql.connect()
    # print(successed)
    # print(msg)
    print("数据库连接是否成功：")
    print(mssql.Connected)

    # Demo1：查询数据
    sql="SELECT TOP 2 P_CusName,P_Tel FROM Dt_Customers WITH(NOLOCK)"
    print("🌸Demot1：获取客户：")
    humans=mssql.get(sql)
    print(humans)

    # Demo2：执行无参存储过程
    # (successed,msg) = mssql.execProc("Usp_TestNoArgs")
    # print("🌸Demot2：执行无参存储过程(Usp_TestNoArgs)：")
    # print(successed,msg)

    # Demo3：执行带参存储过程
    # (successed,msg) = mssql.execProc("Usp_TestWithArgs",(99,"1号机"))
    # print("🌸Demot3：执行带参存储过程(Usp_TestWithArgs)：")
    # print(successed,msg)

    # Demo4：执行存储过程并返回数据
    # (successed,msg,datas) = mssql.execProcGet("Usp_Test",("",))
    # print("🌸Demot4：执行存储过程并返回数据(Usp_Test)：")
    # print(successed,msg,datas)

    # Demo5：Insert
    # user1 = {"P_UserName": "张三", "P_Age": 25, "P_Email": "Zhang3@example.com"}
    # user2 = {"P_UserName": "李四", "P_Age": 20, "P_Email": "Li4@example.com"}
    # user3 = {"P_UserName": "王五", "P_Age": 18, "P_Email": "Wang5@example.com"}
    # (successed,msg)=mssql.insert("Dt_User",user1)
    # (successed,msg)=mssql.insert("Dt_User",user2)
    # (successed,msg)=mssql.insert("Dt_User",user3)
    # print(successed,msg)

    # Demo6：Update
    # updateData = {"P_Age": 31,"P_Email":"Zhang3@QQ.com"}
    # (successed,msg)=mssql.update("Dt_User", updateData, "P_UserName = ?",('张三',))
    # print(successed,msg)

    # Demo7：Delete
    # (successed,msg)=mssql.delete("Dt_User", "P_UserName = ?", ("王五",))
    # print(successed,msg)

    # Demo8：Select
    # cols=("P_UserName","P_Age")
    # cols=None
    # (successed,msg,data)=mssql.select("Dt_User",cols,"P_UserName = ?",("张三",))
    # print(successed,msg,data)

    # 提交事务
    mssql.commit()
    # 关闭
    mssql.close()
```
