DBS:同学录

数据库设计与实现:同学录系统
ylbtech-DatabaseDesgin:ylbtech-cnblogs(博客园)-数据库设计-2,Admin(用户后台)

DatabaseName:同学录

Model:

Type:

Url:

1.A,数据库关系图(Database Diagram) 返回顶部

 

1.B,数据库设计脚本(Database Design Script)返回顶部
-- =============================================
-- Create database template
-- =============================================
USE master
GO

-- Drop the database if it already exists
IF  EXISTS (
    SELECT name 
        FROM sys.databases 
        WHERE name = N'classbook'
)
DROP DATABASE classbook
GO

CREATE DATABASE classbook
GO
use classbook
go
-- =============================================
-- Create Table 班级表
-- =============================================
create table class
(
classid int identity primary key,    --编号
name varchar(100) not null            --名称
)
-- =============================================
-- Create Table 留言表
-- =============================================
create table newsboard
(
newsboardid int identity primary key,    --编号
title varchar(2000) not null,            --名称
username varchar(20),                    --留言人
headimage varchar(100),                    --头像
pubdate datetime default(getdate())        --留言时间
)
-- =============================================
-- Create Table 用户表
-- =============================================
create table users
(
usersid int identity(720001,1) primary key,        --编号
pwd varchar(20) not null,                --密码
[power] varchar(20) check([power]='admin' or [power]='guest') default('guest'),    --级别
pubdate datetime default(getdate())        --申请日期
)
-- =============================================
-- Create Table 学生表
-- =============================================
create table student
(
studentid int identity primary key,        --编号
name varchar(20),                --姓名
sex varchar(2) check(sex=''or sex='') default(''),    --性别
age int,                                --年龄
qq varchar(100),                        --QQ号
[e-mail] varchar(100),                    --邮箱
tel varchar(100),                        --固话
address varchar(1000),                    --所在地
phone varchar(100),                        --电话
headimage varchar(1000),                --头像图片
classid int  foreign key references class(classid) not null, --班级编号
usersid int foreign key references users(usersid) not null     --用户编号    
)
-- =============================================
-- Create Table 短信表
-- =============================================
create table messages
(
messageid int identity(720001,1) primary key,--编号
title varchar(1000),                         --标题    
body varchar(2000),                            --内容
pubdate datetime default(getdate()),        --发布日期
inboxid int,                                --发信人的编号
outboxid int,                                --收信人的编号
inboxname varchar(20),                        --发信人姓名    
outboxname varchar(20),                        --收信人姓名
dal int default(0)                            --是否已读,0:没读,1:已读
)
--插入一些测试信息
insert users(pwd,[power]) values('888888','admin')
insert class(name) values('T03')
select @@identity
select * from class
select * from users
select * from newsboard
select * from student
select * from messages

insert student(name,sex,age,qq,[e-mail],tel,address,phone,classid,usersid)
values('','','','','','','','',1,720001)
insert student(name,sex,age,qq,e-mail,tel,address,phone,classid,usesrid)
values()

select studentid,name,sex,age,qq,[e-mail],tel,address,phone,headimage,classid,usersid from student
select studentid from student where usersid=720002
View Code
1.C,功能实现代码(Function Implementation Code)返回顶部

 

warn作者:ylbtech
出处:http://ylbtech.cnblogs.com/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
根据你的描述,问题的核心在于编译器无法找到从 `std::map<int32_t, mx::dba::dbs::TextureMapTableInDB>` 到 `std::map<int32_t, mx::dba::dbs::TextureMapTableData>` 的适当转换。这通常是因为两个 `std::map` 的值类型不同(`TextureMapTableInDB` 和 `TextureMapTableData`),而 C++ 标准库中的 `std::map` 不支持隐式类型转换。 以下是解决方案和详细解释: --- ### 解决方案 #### 方法 1:显式类型转换 如果 `TextureMapTableInDB` 和 `TextureMapTableData` 之间存在某种映射关系或转换逻辑,可以通过显式转换来解决。例如,可以定义一个函数将 `TextureMapTableInDB` 转换为 `TextureMapTableData`。 以下是示例代码: ```cpp #include <iostream> #include <map> #include <string> // 定义两个结构体 struct TextureMapTableInDB { int id; std::string name; }; struct TextureMapTableData { int id; std::string name; // 构造函数用于从 TextureMapTableInDB 转换 TextureMapTableData(const TextureMapTableInDB& db) : id(db.id), name(db.name) {} }; // 显式类型转换函数 std::map<int32_t, TextureMapTableData> ConvertToData(const std::map<int32_t, TextureMapTableInDB>& dbMap) { std::map<int32_t, TextureMapTableData> dataMap; for (const auto& [key, value] : dbMap) { dataMap[key] = TextureMapTableData(value); // 使用构造函数进行转换 } return dataMap; } int main() { // 创建一个 TextureMapTableInDB 的 map std::map<int32_t, TextureMapTableInDB> dbMap = { {1, {1, "Texture1"}}, {2, {2, "Texture2"}} }; // 转换为 TextureMapTableData 的 map std::map<int32_t, TextureMapTableData> dataMap = ConvertToData(dbMap); // 打印结果 for (const auto& [key, value] : dataMap) { std::cout << "Key: " << key << ", ID: " << value.id << ", Name: " << value.name << std::endl; } return 0; } ``` --- ### 代码解释 1. **结构体定义**: - 定义了两个结构体 `TextureMapTableInDB` 和 `TextureMapTableData`。 - `TextureMapTableData` 包含一个构造函数,可以从 `TextureMapTableInDB` 进行初始化。 2. **转换函数**: - `ConvertToData` 函数接受一个 `std::map<int32_t, TextureMapTableInDB>` 并返回一个 `std::map<int32_t, TextureMapTableData>`。 - 遍历输入的 `dbMap`,使用构造函数将每个 `TextureMapTableInDB` 转换为 `TextureMapTableData`。 3. **主函数**: - 创建了一个 `std::map<int32_t, TextureMapTableInDB>` 并填充数据。 - 调用 `ConvertToData` 函数将其转换为 `std::map<int32_t, TextureMapTableData>`。 - 打印转换后的结果。 --- #### 方法 2:使用模板和类型推导 如果需要更通用的解决方案,可以使用模板和类型推导来实现类型转换。以下是一个示例: ```cpp #include <iostream> #include <map> #include <string> // 定义两个结构体 struct TextureMapTableInDB { int id; std::string name; }; struct TextureMapTableData { int id; std::string name; // 构造函数用于从 TextureMapTableInDB 转换 TextureMapTableData(const TextureMapTableInDB& db) : id(db.id), name(db.name) {} }; // 模板转换函数 template<typename TSrc, typename TDst> std::map<int32_t, TDst> ConvertMap(const std::map<int32_t, TSrc>& srcMap) { std::map<int32_t, TDst> dstMap; for (const auto& [key, value] : srcMap) { dstMap[key] = TDst(value); // 使用构造函数进行转换 } return dstMap; } int main() { // 创建一个 TextureMapTableInDB 的 map std::map<int32_t, TextureMapTableInDB> dbMap = { {1, {1, "Texture1"}}, {2, {2, "Texture2"}} }; // 使用模板函数进行转换 std::map<int32_t, TextureMapTableData> dataMap = ConvertMap(dbMap); // 打印结果 for (const auto& [key, value] : dataMap) { std::cout << "Key: " << key << ", ID: " << value.id << ", Name: " << value.name << std::endl; } return 0; } ``` --- ### 代码解释 1. **模板函数**: - `ConvertMap` 是一个模板函数,接受任意类型的 `std::map` 并返回另一个类型的 `std::map`。 - 使用 `TDst(value)` 进行类型转换,前提是 `TDst` 提供了从 `TSrc` 的构造函数。 2. **主函数**: - 调用 `ConvertMap` 函数时,编译器会自动推导出 `TSrc` 和 `TDst` 的类型。 --- ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值