|
一.將CString轉為CTime的幾種方法
CString timestr = "2000年04月05日";
int a,b,c ;
sscanf(timestr.GetBuffer(timestr.GetLength()),"%d年%d月%d日",&a,&b,&c);
CTime time(a,b,c,0,0,0);
--------or - ---------------------
CString s("2001-8-29 19:06:23");
int nYear, nMonth, nDate, nHour, nMin, nSec;
sscanf(s, "%d-%d-%d %d:%d:%d", &nYear, &nMonth, &nDate, &nHour, &nMin, &nSec);
CTime t(nYear, nMonth, nDate, nHour, nMin, nSec);
---- or ------------------------
CString timestr = "2000年04月05日";
int year,month,day;
BYTE tt[5];
//get year
memset(tt, 0, sizeof(tt));
tt[0] = timestr[0];
tt[1] = timestr[1];
tt[2] = timestr[2];
tt[3] = timestr[3];
year= atoi((char *)tt);
//get month
memset(tt, 0, sizeof(tt));
tt[0] = timestr[6];
tt[1] = timestr[7];
month = atoi((char *)tt);
//get day
memset(tt, 0, sizeof(tt));
tt[0] = timestr[10];
tt[1] = timestr[11];
CTime time(year,month,day,0,0,0);
從上面來看,很明顯使用sscanf()函數(shù)的優(yōu)勢.
二.將CTIme轉換為CString的方法:
CTime tmSCan = CTime::GetCurrentTime();
CString szTime = tmScan.Format("'%Y-%m-%d %H:%M:%S'");
這樣得到的日期時間字符串就是以"2006-11-27 23:30:59"的格式.這是不是很方便呢?
//取得CTime中的日期
CString cstrDate = tmScan.Format("%Y-%m-%d");
//取得CTime中的時間
CString cstrTime = tmScan.Format("%H:%M-%S");
sprintf還有個不錯的表妹:strftime,專門用于格式化時間字符串的,用法跟她表哥很像,也是一大堆格式控制符,只是畢竟小姑娘家心細,她還要調用者指定緩沖區(qū)的最大長度,可能是為了在出現(xiàn)問題時可以推卸責任吧。這里舉個例子:
更多更好的sprintf()函數(shù)說明參考:《spirntf,你知道多少?》
http://blog.csdn.net/steedhorse/archive/2005/03/25/330206.aspx
time_t t = time(0);
//產(chǎn)生"YYYY-MM-DD hh:mm:ss"格式的字符串。
char s[32];
strftime(s, sizeof(s), "%Y-%m-%d %H:%M:%S", localtime(&t));
sprintf在MFC中也能找到他的知音:CString::Format,strftime在MFC中自然也有她的同道:CTime::Format,這一對由于從面向對象哪里得到了贊助,用以寫出的代碼更覺優(yōu)雅。
Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=1417748
SQL Server 2000中,當新建一個空的數(shù)據(jù)庫后,在查詢分析器中執(zhí)行
sp_database 或select * from sysobjects where xtype = 'U'
都會得到dtproperties表,并顯示為用戶表, 可這個表我從沒有創(chuàng)建過。但是在企業(yè)管理器中,dtproperties卻顯示為系統(tǒng)表。難道是bug ? 查看dtproperties,里面沒有數(shù)據(jù),是個空表。在SQL Server聯(lián)機叢書里沒有關于這個表的描述。
dtproperties表在企業(yè)管理器中無法刪除,但在查詢分析器中 執(zhí)行drop table dtproperties卻可以刪除。
手工建立一個表,表名就叫dtproperties,然后再查看,在企業(yè)管理器中赫然顯示為系統(tǒng)表??! 看來Bug是一定的了。
重新創(chuàng)建一個數(shù)據(jù)庫, 寫個觸發(fā)器,讓其在dtproperties表執(zhí)行insert時執(zhí)行,然后在SQL Server里隨意操作,hehe,終于發(fā)現(xiàn),在新建關系圖時,dtproperties表被插入數(shù)據(jù),看來它是用來存儲數(shù)據(jù)關系圖的。呵呵,想點辦法,數(shù)據(jù)關系圖以后也可以備份下來了。
再用drop table dtproperties刪除表dtproperties,[手工創(chuàng)建dtproperties ,結構任意,] 然后在企業(yè)管理器中新建數(shù)據(jù)關系圖,呵呵,SQL Server報錯!再次證實前面的猜想!
SQL Server 2005中dtproperties 表不存在了,取而代之的是sysdiagram (記不住具體的名稱了) ,這個bug也不存在了,SQL Server 2005中的系統(tǒng)表和SQL Server 2000有了很大的不同。
在數(shù)據(jù)庫內(nèi)創(chuàng)建的每個對象(約束、默認值、日志、規(guī)則、存儲過程等)在表中占一行。只有在 tempdb 內(nèi),每個臨時對象才在該表中占一行。
列名 | 數(shù)據(jù)類型 | 描述 |
---|---|---|
name | sysname | 對象名。 |
Id | int | 對象標識號。 |
xtype | char(2) | 對象類型。可以是下列對象類型中的一種:
C = CHECK 約束 |
uid | smallint | 所有者對象的用戶 ID。 |
info | smallint | 保留。僅限內(nèi)部使用。 |
status | int | 保留。僅限內(nèi)部使用。 |
base_schema_ ver |
int | 保留。僅限內(nèi)部使用。 |
replinfo | int | 保留。供復制使用。 |
parent_obj | int | 父對象的對象標識號(例如,對于觸發(fā)器或約束,該標識號為表 ID)。 |
crdate | datetime | 對象的創(chuàng)建日期。 |
ftcatid | smallint | 為全文索引注冊的所有用戶表的全文目錄標識符,對于沒有注冊的所有用戶表則為 0。 |
schema_ver | int | 版本號,該版本號在每次表的架構更改時都增加。 |
stats_schema_ ver |
int | 保留。僅限內(nèi)部使用。 |
type | char(2) | 對象類型??梢允窍铝兄抵唬?
C = CHECK 約束 |
userstat | smallint | 保留。 |
sysstat | smallint | 內(nèi)部狀態(tài)信息。 |
indexdel | smallint | 保留。 |
refdate | datetime | 留作以后使用。 |
version | int | 留作以后使用。 |
deltrig | int | 保留。 |
instrig | int | 保留。 |
updtrig | int | 保留。 |
seltrig | int | 保留。 |
category | int | 用于發(fā)布、約束和標識。 |
cache | smallint | 保留。 |
系統(tǒng)表用的不多,寫幾個常用的系統(tǒng)表
各個數(shù)據(jù)庫中的系統(tǒng)表:
1.SysObject:
? 存放數(shù)據(jù)庫中的各個對象!
? 最重字段
?? 1.1 Name,Id,Crdate,Xtype (U :用戶表,V:視圖,Tr:觸發(fā)器,P:存儲過程,S,系統(tǒng)表)
?? 1.2 常用函數(shù) Object_ID('對象名'),Object_Name?
?? 此外我們?nèi)绻肷?,2,3,4,5這樣的等差數(shù)列,可以這樣做
?? Select Identity(int,1,1) As Id Into # From SysObjects,SysColumns??
2.SysColumns
? 存放各列的信息
? 最重字段
?? 2.1 Name,Id,Colid--字段在表中存放的順序
?? 設一個表中字段有很多,想列出某表除某字段外的所有字段,可以這樣寫
?? Declare @Fields Varchar(5000)
?? Select @Fields=@Fields+Name
?? From SysColumns
?? Where Id=Object_ID('Test') and Name Not In ('字段1','字段2')
?? 又如如何用列序號選擇特定列
?? Create Function F_ColumnOrder(@TableName Varchar(10),@Colid Int)
?? Returns Table
?? As
?? Return
?? Select Name From SysColumns
?? Where ID=Object_ID(@TableName) And Colid=@Colid
--Try
Select * From Dbo.F_ColumnOrder('Users',2)
??
3.SysFiles
? 如果我們想知道SQL的數(shù)據(jù)文件存放目錄的話,可以用
? Select FileName From SysFiles
4.SysComments
? 保存視圖或存儲過程的語句!
5.Sysforeignkeys
? fkeyid:外鍵表對象ID,rKeyid:主鍵表對象ID
有時我們想把數(shù)據(jù)庫中的所有表都去掉,但是有約束的存在,有些表必須在主表前刪除,否則就會報錯,
這種情況下我們就通過該表來實現(xiàn)
**********************************************************
Master表中的系統(tǒng)表
SysDataBases
? 重要字段
??? 1.1 Name,Dbid,Crdate
????? 常用函數(shù) DB_ID('數(shù)據(jù)庫名')
sysaltfiles
??? 保存各個數(shù)據(jù)庫的MDF文件的物理地址
SysProcesses
??? 保存進程信息
??? Kill? spid 殺掉某進程
5.注意sp_MsForEachTable函數(shù)
? 刪除某數(shù)據(jù)庫中表
?? Exec Sp_MsForEachTable 'Truncate Table ?'
?? 注意:有約束的不能刪除,會出錯的
6.如果想改系統(tǒng)表怎么辦?
? 2種方法
??? 1.通過查詢分析器改
??? 用如下語句:
???? Exec Sp_Configure 'allow updates',1--允計修改
???? Reconfigure with override
????
???? Exec Sp_Configure 'allow updates',0--不允計修改
???? Reconfigure with override????
??? 2.通過企業(yè)管理器改
???? 在SQL實例上右鍵-屬性-允計修改系統(tǒng)目錄直接進行修改