在 SQL Server 数据库中保存字体的最佳方法

发布于 2024-12-05 18:41:26 字数 501 浏览 0 评论 0原文

在知道可以从不同环境 (Windows/Linux) 和语言 (Java/PHP/Python/C#) 访问该字体的情况下,在 SQL Server 数据库中插入字体的最佳方法是什么?

我有一个例子,我应该从 C# Winforms 应用程序插入字体并从 Java 应用程序获取此字体,目前我正在插入 Font.NameFont.StyleFont.Size 并从 Java 我使用 Font.Decode(); 方法检索字体。

它在很多情况下都有效,但我认为最好将字体文件传输到数据库,并通过关联自定义构造的字符串来识别字体,从数据库获取字体文件 .ttf其关联文件。

例如:字体名称字体大小字体样式 + 字体文件,因为有时未安装该字体或在另一个系统上有不同的名称(字体在我的情况下非常重要)。

Which is the best way to insert a font in a SQL Server database, while knowing that this font can accessed from different environments (Windows/Linux) and languages (Java/PHP/Python/C#)?

I have a case where I should insert a Font from a C# Winforms application and get this font from Java application, and currently I'm inserting Font.Name, Font.Style and Font.Size and from Java I'm retrieving the font using Font.Decode(); method.

And it works in many cases, but I thought it might be better to transfer the font file to the database and get the font file .ttf from the database by associating a custom constructed string to identify the font with its associated file.

eg: Font Name, Font Size and Font Style + Font File, because sometimes that font is not installed or has a different name on another system (font is very important in my case).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鱼忆七猫命九 2024-12-12 18:41:26

微软研究院有一篇非常好的论文,名为To Blob or Not To Blob。

他们经过大量性能测试和分析后得出的结论是:

  • 如果您的图片或文档大小通常低于 256K,则将它们存储在数据库 VARBINARY 列中效率更高

  • 如果图片或文档大小通常超过 1 MB,将它们存储在文件系统中效率更高(并且使用 SQL Server 2008 的 FILESTREAM 属性,它们仍然处于事务控制之下并且是数据库的一部分)

  • ,根据您的使用情况,这有点难以抉择

如果您决定将图片放入 SQL Server 表中,我强烈建议使用单独的表来存储这些图片 - 不要将员工照片存储在员工表中- 将它们放在单独的表中。这样,假设您并不总是需要选择员工照片作为查询的一部分,那么 Employee 表就可以保持精简、简洁且非常高效。

对于文件组,请查看文件和文件组体系结构了解简介。基本上,您可以从一开始就为大型数据结构创建具有单独文件组的数据库,或者稍后添加其他文件组。我们称之为“LARGE_DATA”。

现在,每当您要创建一个需要存储 VARCHAR(MAX) 或 VARBINARY(MAX) 列的新表时,您都可以为大数据指定此文件组:

 CREATE TABLE dbo.YourTable
     (....... define the fields here ......)
     ON Data                   -- the basic "Data" filegroup for the regular data
     TEXTIMAGE_ON LARGE_DATA   -- the filegroup for large chunks of data

查看有关文件组的 MSDN 介绍,并使用它!

There's a really good paper by Microsoft Research called To Blob or Not To Blob.

Their conclusion after a large number of performance tests and analysis is this:

  • if your pictures or document are typically below 256K in size, storing them in a database VARBINARY column is more efficient

  • if your pictures or document are typically over 1 MB in size, storing them in the filesystem is more efficient (and with SQL Server 2008's FILESTREAM attribute, they're still under transactional control and part of the database)

  • in between those two, it's a bit of a toss-up depending on your use

If you decide to put your pictures into a SQL Server table, I would strongly recommend using a separate table for storing those pictures - do not store the employee foto in the employee table - keep them in a separate table. That way, the Employee table can stay lean and mean and very efficient, assuming you don't always need to select the employee foto, too, as part of your queries.

For filegroups, check out Files and Filegroup Architecture for an intro. Basically, you would either create your database with a separate filegroup for large data structures right from the beginning, or add an additional filegroup later. Let's call it "LARGE_DATA".

Now, whenever you have a new table to create which needs to store VARCHAR(MAX) or VARBINARY(MAX) columns, you can specify this file group for the large data:

 CREATE TABLE dbo.YourTable
     (....... define the fields here ......)
     ON Data                   -- the basic "Data" filegroup for the regular data
     TEXTIMAGE_ON LARGE_DATA   -- the filegroup for large chunks of data

Check out the MSDN intro on filegroups, and play around with it!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文