Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


New Code formatting engine rolled out


New Code formatting engine rolled out

Author
Message
Ben Adderson
Ben Adderson
Forum Newbie
Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)

Group: Administrators
Points: 7 Visits: 274
We've now updated the syntax highlighting here on the forums. We've also tweaked the IFCodes to try and clarify which should be used for what. The revised list of tags are as follows:

[ code ] - Will default to SQL highlighting
[ code ="sql" ] - SQL highlighting
[ code ="xml" ] - XML highlighting
[ cpde="vb" ] - VB highlighting
[ code ="other" ] - Any other code you'd like highlighted. This option relies on the highlighter to determine the language, so YMMV. As we're using Google Code Prettify, you can find more details on the supported languages here
[ code ="plain" ] - This option just provides a fixed font, for when you don't want syntax highlighting, or the "other" option is not satisfactory.

I've updated the IFCode Shortcuts, so the new Codes should appear in the list when you're composing a post.

Here are some (pretty vanilla) examples from me, using the new Codes:

Using [ code ]:

SELECT *
FROM Customers
WHERE CustomerId = 123456



Using [ code="sql" ]

SELECT *
FROM Customers
WHERE CustomerId = 123456



Using [ code="xml" ]

<xml>
<customer id="123456">
<name>John Doe</name>
</customer>
</xml>



Using [ code="vb" ]

Imports System

Class [class]
Shared Sub [shared](ByVal [boolean] As Boolean)
If [boolean] Then
Console.WriteLine("true")
Else
Console.WriteLine("false")
End If
End Sub
End Class

Module [module]
Sub Main()
[class].[shared](True)

' This prints out: ".
Console.WriteLine("""")

' This prints out: a"b.
Console.WriteLine("a""b")

' This prints out: a.
Console.WriteLine("a"c)

' This prints out: ".
Console.WriteLine(""""c)
End Sub
End Module

Dim d As Date
d = # 8/23/1970 3:45:39AM #
d = # 8/23/1970 #
d = # 3:45:39AM #
d = # 3:45:39 #
d = # 13:45:39 #
d = # 13:45:39PM #

Dim n As Float
n = (0.0, .99F, 1.0E-2D, 1.0E+3D, .5E4, 1E3R, 4D)

Dim i As Integer
i = (0, 123, 45L, &HA0I, &O177S)



Using [ code="other" ]

public class HelloWorld()
{
public static void main(string[] args)
{
Console.Writeline("Hello World!")
}
}



Using [ code="plain" ]

public class HelloWorld()
{
public static void main(string[] args)
{
Console.Writeline("Hello World!")
}
}


I've created this new thread (rather than post in this old one) so we can keep track of any issues/bugs with the new engine. If you run into any problems, please let us know by posting them here!

Thanks!

Ben Adderson
Web Tester
Red Gate Software
RBarryYoung
RBarryYoung
SSCrazy Eights
SSCrazy Eights (9.4K reputation)SSCrazy Eights (9.4K reputation)SSCrazy Eights (9.4K reputation)SSCrazy Eights (9.4K reputation)SSCrazy Eights (9.4K reputation)SSCrazy Eights (9.4K reputation)SSCrazy Eights (9.4K reputation)SSCrazy Eights (9.4K reputation)

Group: General Forum Members
Points: 9438 Visits: 9517
So [ code="vb" ] has been removed then? Wow, that's a bummer.

I have tried to replace it with [ code="other" ], unfortunately, "other" seems to mean C/C++/C#/Java or anything else that looks like C. It completely messes up the comment's for VB programs (because it treats them like a C/C++/C#/Java quotation mark). ... Sad

-- RBarryYoung, (302)375-0451 blog: MovingSQL.com, Twitter: @RBarryYoung
Proactive Performance Solutions, Inc.
"Performance is our middle name."
GSquared
GSquared
SSChampion
SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)

Group: General Forum Members
Points: 14375 Visits: 9729
I like that my tab indents don't go all wonky with the SQL one. Hadn't tried that option before, but noticed it on the bar and tried it a few days ago. Very nice.

- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread

"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
RBarryYoung
RBarryYoung
SSCrazy Eights
SSCrazy Eights (9.4K reputation)SSCrazy Eights (9.4K reputation)SSCrazy Eights (9.4K reputation)SSCrazy Eights (9.4K reputation)SSCrazy Eights (9.4K reputation)SSCrazy Eights (9.4K reputation)SSCrazy Eights (9.4K reputation)SSCrazy Eights (9.4K reputation)

Group: General Forum Members
Points: 9438 Visits: 9517
What's really odd is that according to Goggle, this problem (VB comments) was fixed back in January.

-- RBarryYoung, (302)375-0451 blog: MovingSQL.com, Twitter: @RBarryYoung
Proactive Performance Solutions, Inc.
"Performance is our middle name."
Jeff Moden
Jeff Moden
SSC-Forever
SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)

Group: General Forum Members
Points: 45127 Visits: 39923
Just testing....

/**********************************************************************************************************************
Purpose:
Returns a single result set similar to sp_Space used for all user tables at once.

Notes:
1. May be used as a view, stored procedure, or table-valued funtion. 2. Must comment out 1 "Schema" in the SELECT list below prior to use. See the adjacent comments for more info.

Revision History:
Rev 00 - 22 Jan 2007 - Jeff Moden
- Initital creation for SQL Server 2000
Rev 01 - 11 Mar 2007 - Jeff Moden
- Add automatic page size determination for future compliance
Rev 02 - 05 Jan 2008 - Jeff Moden
- Change "Owner" to "Schema" in output. Add optional code per Note 2 to find correct schema name
**********************************************************************************************************************/
--===== Ensure that all row counts, etc is up to snuff
-- Obviously, this will not work in a view or UDF and should be removed if in a view or UDF. External code should
-- execute the command below prior to retrieving from the view or UDF.
DBCC UPDATEUSAGE(0) WITH COUNT_ROWS, NO_INFOMSGS

--===== Return the single result set similar to what sp_SpaceUsed returns for a table, but more
SELECT DBName = DB_NAME(),
SchemaName = SCHEMA_NAME(so.UID), --Comment out if for SQL Server 2000
--SchemaName = USER_NAME(so.UID), --Comment out if for SQL Server 2005
TableName = so.Name,
TableID = so.ID/*just a test*/,
MinRowSize = MIN(si.MinLen),
MaxRowSize = MAX(si.XMaxLen),
ReservedKB = SUM(CASE WHEN si.IndID IN (0,1,255) THEN si.Reserved ELSE 0 END) * pkb.PageKB,
DataKB = SUM(CASE WHEN si.IndID IN (0,1 ) THEN si.DPages ELSE 0 END) * pkb.PageKB
+ SUM(CASE WHEN si.IndID IN ( 255) THEN ISNULL(si.Used,0) ELSE 0 END) * pkb.PageKB,
IndexKB = SUM(CASE WHEN si.IndID IN (0,1,255) THEN si.Used ELSE 0 END) * pkb.PageKB
- SUM(CASE WHEN si.IndID IN (0,1 ) THEN si.DPages ELSE 0 END) * pkb.PageKB
- SUM(CASE WHEN si.IndID IN ( 255) THEN ISNULL(si.Used,0) ELSE 0 END) * pkb.PageKB,
UnusedKB = SUM(CASE WHEN si.IndID IN (0,1,255) THEN si.Reserved ELSE 0 END) * pkb.PageKB
- SUM(CASE WHEN si.IndID IN (0,1,255) THEN si.Used ELSE 0 END) * pkb.PageKB,
Rows = SUM(CASE WHEN si.IndID IN (0,1 ) THEN si.Rows ELSE 0 END),
RowModCtr = MIN(si.RowModCtr),
HasTextImage = MAX(CASE WHEN si.IndID IN ( 255) THEN 1 ELSE 0 END),
HasClustered = MAX(CASE WHEN si.IndID IN ( 1 ) THEN 1 ELSE 0 END)
FROM dbo.SysObjects so,
dbo.SysIndexes si,
(--Derived table finds page size in KB according to system type
SELECT Low/1024 AS PageKB --1024 is a binary Kilo-byte
FROM Master.dbo.spt_Values
WHERE Number = 1 --Identifies the primary row for the given type
AND Type = 'E'--Identifies row for system type
) pkb
WHERE si.ID = so.ID
AND si.IndID IN (0, --Table w/o Text or Image Data
1, --Table with clustered index
255) --Table w/ Text or Image Data
AND so.XType = 'U' --User Tables
AND PERMISSIONS(so.ID) <> 0
GROUP BY so.Name,
so.UID,
so.ID,
pkb.PageKB
ORDER BY ReservedKB DESC

SELECT '(1)Sad1)'



--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
Although they tell us that they want it real bad, our primary goal is to ensure that we dont actually give it to them that way.
Although change is inevitable, change for the better is not.
Just because you can do something in PowerShell, doesnt mean you should. Wink

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
Jeff Moden
Jeff Moden
SSC-Forever
SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)

Group: General Forum Members
Points: 45127 Visits: 39923
Ben Adderson (9/28/2009)
We've now updated the syntax highlighting here on the forums. We've also tweaked the IFCodes to try and clarify which should be used for what. The revised list of tags are as follows:


Ben, there are a couple of minor things I need to watch for but I think the change is freakin' awesome! And, it's pretty fast, too! My hat is off to you and anyone else who may have brought this change to pass. No more wrapped lines. No more skipped blank lines. No more having to insert & # 160 ; to keep a blank line. No more posts that are a thousand miles wide. And, not only can I now use IFCode's within an SQL block to help drive a point home for someone, but the end of line markers actually work without first having to paste into WORD or whatever! YEEEEE-HAAAA!!!! You, Sir, have made me a very happy frequent poster. It's been a long time coming and I have to say "Well done!" and thank you, thank you, thank you!

--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
Although they tell us that they want it real bad, our primary goal is to ensure that we dont actually give it to them that way.
Although change is inevitable, change for the better is not.
Just because you can do something in PowerShell, doesnt mean you should. Wink

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
Matt Whitfield
Matt Whitfield
SSC-Addicted
SSC-Addicted (497 reputation)SSC-Addicted (497 reputation)SSC-Addicted (497 reputation)SSC-Addicted (497 reputation)SSC-Addicted (497 reputation)SSC-Addicted (497 reputation)SSC-Addicted (497 reputation)SSC-Addicted (497 reputation)

Group: General Forum Members
Points: 497 Visits: 719
If you wanted to extend it for VB / VB.NET / C# - then you might want to consider ActiPro CodeHighlighter - @ http://www.actiprosoftware.com/Products/DotNet/ASPNET/CodeHighlighter/Default.aspx.

Not sure if it's relevant to you or not, just thought I'd mention it because it's free and the quality of the their products is very high...

Atlantis Interactive - SQL Server Tools
My blog
Why I wrote a sql query analyzer clone
Ben Adderson
Ben Adderson
Forum Newbie
Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)

Group: Administrators
Points: 7 Visits: 274
RBarryYoung (9/30/2009)
So [ code="vb" ] has been removed then? Wow, that's a bummer.

I have tried to replace it with [ code="other" ], unfortunately, "other" seems to mean C/C++/C#/Java or anything else that looks like C. It completely messes up the comment's for VB programs (because it treats them like a C/C++/C#/Java quotation mark). ... Sad


Hi Barry,

I've just added [ code="vb" ] Smile

I've updated my original post with an example, but I'm not very familiar with VB, so if you could give it a try and let us know about any issues, that would be great!

Ben Adderson
Web Tester
Red Gate Software
RBarryYoung
RBarryYoung
SSCrazy Eights
SSCrazy Eights (9.4K reputation)SSCrazy Eights (9.4K reputation)SSCrazy Eights (9.4K reputation)SSCrazy Eights (9.4K reputation)SSCrazy Eights (9.4K reputation)SSCrazy Eights (9.4K reputation)SSCrazy Eights (9.4K reputation)SSCrazy Eights (9.4K reputation)

Group: General Forum Members
Points: 9438 Visits: 9517
Ben Adderson (10/5/2009)
RBarryYoung (9/30/2009)
So [ code="vb" ] has been removed then? Wow, that's a bummer.

I have tried to replace it with [ code="other" ], unfortunately, "other" seems to mean C/C++/C#/Java or anything else that looks like C. It completely messes up the comment's for VB programs (because it treats them like a C/C++/C#/Java quotation mark). ... Sad


Hi Barry,

I've just added [ code="vb" ] Smile

I've updated my original post with an example, but I'm not very familiar with VB, so if you could give it a try and let us know about any issues, that would be great!

Yup, looks good.

For future reference, here is an example:

'APP_DataBase (vba)
'
' This is the module for the APP application's
'Database functions, routines and constants.
'
'2007-06-08 B.Young Created
'
Option Explicit

Public appDB As New ADODB.Connection


Public Function IsOpenDB() As Boolean
' function to track the DB status
IsOpenDB = (appDB.State <> 0) ' 0=closed
End Function

Public Sub CloseDB()
'Close the database if it is open.
If IsOpenDB Then appDB.Close
End Sub

Public Function OpenDB() As Boolean
'Open the Database and indicate if sucessful
Static sPrev As String
Dim sFile As String

If IsOpenDB Then
OpenDB = True 'we are already open
Exit Function
End If

If sPrev = "" Then sPrev = GetSetting(APP_AppName, "History", "DBName")

With Application.FileDialog(msoFileDialogFilePicker)
'specify the file open dialog
.AllowMultiSelect = False
.Filters.Clear
.Filters.Add "Access Workbooks", "*.mdb"
.Filters.Add "All Files", "*.*"
.InitialFileName = sPrev
.Title = "Open TIP Database"

.Show

If .SelectedItems.Count > 0 Then
sFile = .SelectedItems(1)
Else 'user canceled ...
OpenDB = False
Exit Function
End If
End With

'appDB.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\byoung\APP\Main.mdb"
appDB.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & sFile
On Error Resume Next
appDB.Open
If Err.Number <> 0 Then
MsgBox "Error(" & Err.Number & "): " & Err.Description, vbOKOnly + vbCritical, "Error in OpenDB"
OpenDB = False
Exit Function
End If

'Opened ok, so finsh-up and exit
OpenDB = True
sPrev = sFile
SaveSetting APP_AppName, "History", "DBName", sPrev

End Function

Public Function DBLookup(SQLCommand As String, Optional DefaultVal As Variant = "") As Variant
'Execute a SQL statement and return a single value.
Dim rs As Recordset

On Error GoTo ErrHandler 'Handle any/all DB errors

If Not IsOpenDB Then OpenDB

' execute the command
Set rs = appDB.Execute(SQLCommand)

' extract the first field of the first record returned
rs.MoveFirst
DBLookup = rs.Fields(0).Value
Exit Function

ErrHandler:
' whatever the error is, just assign the default value and return
DBLookup = DefaultVal
Exit Function
End Function

Public Sub DBExecute(SQLCommand As String, Optional RecordsAffected As Long = 0)
'Execute a SQL statement that returns no values.

If Not IsOpenDB Then OpenDB

appDB.Execute SQLCommand, RecordsAffected

End Sub

'===================



Thanks!

-- RBarryYoung, (302)375-0451 blog: MovingSQL.com, Twitter: @RBarryYoung
Proactive Performance Solutions, Inc.
"Performance is our middle name."
GilaMonster
GilaMonster
SSC-Forever
SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)

Group: General Forum Members
Points: 47263 Visits: 44392
Testing....

Using an inequality character
SELECT session_id FROM sys.dm_exec_requests WHERE session_id > 50



Using escape codes for inequality
SELECT session_id FROM sys.dm_exec_requests WHERE session_id > 50



Using angle brackets to designate a placeholder
USE <Database Name>



Using escape codes to designate a placeholder
USE <Database Name>



Edit: Ok, can someone tell me the secret to posting angle brackets please?


Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search